Newbie: Is there a more pythonic approach?

Martin von Loewis loewis at informatik.hu-berlin.de
Wed Mar 14 06:20:25 EST 2001


Lloyd Sommerer <lsommerer at sewardweb.com> writes:

> a) made use of python language features in a way that seems natural to
> "real" python programmers.

I could understand your script quite easily, and could not detect any
'misuse'.


> b) missed any language construction that makes the program "better"
> (faster, easier to read...)

To see whether a number of files exist, you can take two approaches:
1. construct the file names, and see which file exists
2. list the directory (os.listdir) and see whether you recognize any of
   the file names

Which one is more efficient much depends on the number of files in
each directory and on your operating system; if speed matters, I'd
benchmark them both. Your approach (option 1) is certainly easier to
read.

Regards,
Martin



More information about the Python-list mailing list