Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38196

Re: Best Practice Question

Date 2013-02-05 15:32 +0100
From Jean-Michel Pichavant <jeanmichel@sequans.com>
Subject Re: Best Practice Question
Newsgroups comp.lang.python
Message-ID <mailman.1368.1360074859.2939.python-list@python.org> (permalink)

Show all headers | View raw



----- Original Message -----
> On 02/04/2013 11:23 PM, Anthony Correia wrote:
> > Just started learning Python.  I just wrote a simple copy files
> > script. I use Powershell now as my main scripting language but I
> > wanted to extend into the linux platform as well.  Is this the
> > best way to do it?
> >
> > import os
> >
> >      objdir = ("C:\\temp2")
> >      colDir = os.listdir(objdir)
> >      for f in colDir:
> >          activefile = os.path.join(objdir + "\\" + f)
> >          print ("Removing " + activefile + " from " + objdir)
> >          os.remove(activefile)
> >
> > In Powershell I would do this:
> >
> > $colDir = gci -path "c:\temp2"
> > $objDir = "C:\temp3"
> > ForEach($file in $colDir){
> >      #.Fullname lists the directory and filename together.  No need
> >      to do a join
> >      #beforehand.
> >      Copy-item $file.fullname -destination $objDir
> > }
> >
> 
> You started two nearly-identical threads, with nearly the same
> content.
>   I won't repeat the comments already posted in the other thread, but
> notice that your powershell script copies the file, while your Python
> "translation" deletes the file.  Big difference.
> 
> Next, you should use raw strings, or at least use the forward slash,
> rather than double backslashes in file path literals.
> 
> 
> 
> --
> DaveA

He must have hit the send button too early by mistake.
By the way, did someone ever notice that r'\' fails ? I'm sure there's a reason for that... (python 2.5) Anyone knows ?

r'\'
SyntaxError: EOL while scanning single-quoted string

r'\b'
'\\b'


JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Best Practice Question Jean-Michel Pichavant <jeanmichel@sequans.com> - 2013-02-05 15:32 +0100

csiph-web