os.walk/list
Peter Otten
__peter__ at web.de
Mon Mar 21 04:15:26 EDT 2011
ecu_jon wrote:
> yes i agree breaking stuff into smaller chunks is a good way to do it.
> even were i to do something like
>
> def safe_copy()
> f1=file(files ,'rb')
> f2 = file(os.path.join(currentdir,fname,files))
> truth = md5.new(f1.read()).digest() ==
> md5.new(f2.read()).digest()
> if truth == 0:
> print "file copy error"
>
> that would probably work for the single file copy functions. but would
> still breakdown during the for ...os.walk(), again because "fname" is
> a list there, and the crypto functions work 1 file at a time. even
> changing crypto functions wouldn't change that.
That's what function parameters are for:
def safe_copy(fname):
....
for x in fname:
safe_copy(x)
That way fname is a filename inside safe_copy() and a list of filenames on
the global module level. "fname" for a list and "files" for a single file
are still badly chosen names because they confuse the reader instead of
clarifying what's going on.
I strongly recommend that you work through a python tutorial for non-
programmers before you continue with your efforts.
More information about the Python-list
mailing list