regular expression concatenation with strings

oscartheduck oscartheduck at gmail.com
Fri Jun 22 18:44:08 EDT 2007


Oh dear. I just want to make it clear I wasn't trying to take credit
for the change of extension to ext. I genuinely worked it out
independently and then rushed back and posted about it, but you
definitely worked it out and wrote it up first!

Sorry! And thanks for the help!!



James

On Jun 22, 4:07 pm, oscartheduck <oscarthed... at gmail.com> wrote:
> Got it:
>
> #!/usr/bin/env python
> from PIL import Image
> import glob, os, re
>
> size = 128, 128
>
> def thumbnailer(dir, filenameRx):
>      for picture in [ p for p in os.listdir(dir) if
> os.path.isfile(os.path.join(
> dir,p)) and filenameRx.match(p) ]:
>          file, ext = os.path.splitext(picture)
>          im = Image.open (picture)
>          im.thumbnail(size, Image.ANTIALIAS)
>          im.save(file + ".thumbnail" + ext)
>
> jpg = re.compile(".*\.(jpg|jpeg)", re.IGNORECASE)
> thumbnailer(".", jpg)
>
> The answer was sitting in front of my eyes. What is your code doing?
> It looks like:
>
> for $foo in [current working directory]
> if $foo is a file
> and foo's name matches the regex





More information about the Python-list mailing list