Moving around files and fun things of that sort.

Mark McEahern marklists at
Tue Aug 27 14:48:36 EDT 2002

[Micah Mayo]
> x = 0
> for x in range (17):

fwiw, if you have a list, you can enumerate it without the range stuff;

seq = ['a', 'b', 'c']
for letter in seq:
  print letter

Now, if you have source and destination, consider storing them like so:

import shutil

class FileToCopy:

  def __init__(self, source, destination):
    self.source = source
    self.destination = destination

  def copy(self):
    shutil.filecopy(source, destination)

files = []
files.append(FileToCopy('/etc/foo1', '/etc/foo2'))

>     os.system('cp -p source[x] destination[x]')
>     if os.path.getsize(source[x]) != os.path.getsize(destination[x]):
>         print 'Size not verified, do you wish to contnue?'
>         etc..
>         etc..
> (this is pseudo-code, so don't worry about specific syntax)
> my problem is this will not work with the os.system method. There
> isn't a way that I can find that will allow me to mix these arrays
> with the system command. So a) is there a way for python to copy the
> files w/o using the os.system, or is there a way to make os.system
> work?

source = 'foo'
destination = 'bar'
cmd = 'cp -p %s %s' % (source, destination)
print cmd

Does that help?


// mark


More information about the Python-list mailing list