regular expressions eliminating filenames of type foo.thumbnail.jpg

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Jun 25 22:17:03 EDT 2007


En Mon, 25 Jun 2007 19:52:32 -0300, oscartheduck <oscartheduck at gmail.com>  
escribió:

> Well, darn.
>
> I just discovered that the computer this is going to run on only has
> python version 2.2 installed on it, which apparently doesn't support
> checking a whole word, but instead checks a single letter against
> other single letters. 2.4 and, presumably 2.5 though I've actually not
> used it much, has such huge leaps forwards relative to 2.2 that it's
> frightening thinking about where the language is going.
>
> But for now, I'm going to have to work on this problem again from
> scratch, it seems.

You can still use a regular expression:

thumbnailRx = re.compile(r"\.thumbnail\.")

for picture in [... and filenameRx.match(p) and not thumbnailRx.search(p)]:

>>
>> 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) if 'thumbnail' not in p]:
>>          file, ext = os.path.splitext(picture)

-- 
Gabriel Genellina




More information about the Python-list mailing list