On 02Aug2015 16:15, Clayton Kirkwood <c...@godblessthe.us> wrote:
Behalf Of Cameron Simpson
Sent: Sunday, August 02, 2015 3:35 PM
[...]
Personally I'd be reaching for os.path.splitext. Untested example below:

  from os.path import splitext
  ....
  for dir_path, directories, files in os.walk(main_dir):
    for file in files:
      prefix, ext = splitext(file)
      if ext and ext[1:].lower() in ('jpg', 'png', 'avi', 'mp4'):
        ....

which I think is much easier to read.

BTW, I'd be using the variable names "filename" and "filenames" instead of
"file" and "files": in python 2 "file" is a builtin function (though long
deprecated by "open()") and in any case I'd (personally) expect such a
name
to be an _open_ file. As opposed to "filename", which is clearer.

Thanks, that should also help a lot. Now time to look at splitext, and the
ext and ext[1:.

The "[1:]" is because "ext" will include the dot.

I appreciate your comments also about the variable names.
Any comments on the problems lower in the file?

Maybe you'd better reraise these problems again explicitly.

Cheers,
Cameron Simpson <c...@zip.com.au>
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to