[Tutor] scratching my head

Válas Péter turtle at 64.hu
Mon Aug 3 08:34:40 CEST 2015


2015-08-02 23:44 GMT+02:00 Clayton Kirkwood <crk at godblessthe.us>:

>
>
> for dir_path, directories, files in os.walk(main_dir):
>     for file in files:
> #        print( " file = ", file)
> #       if( ("(\.jpg|\.png|\.avi|\.mp4)$") not in file.lower() ):
>
>
> I supppose you want to use regular expressions here and you are somehow
familiar with them but you forgot to tell Python to handle your string as
regex. This kind of expression must be matched against filenames instead of
using "in" operator.

In this case, https://docs.python.org/3/library/re.html and
https://docs.python.org/3/howto/regex.html are your friends.


More information about the Tutor mailing list