Author bochecha
Recipients bochecha
Date 2010-08-13.08:36:48
SpamBayes Score 3.37185e-07
Marked as misclassified No
Message-id <1281688613.27.0.00233773234268.issue9584@psf.upfronthosting.co.za>
In-reply-to
Content
The attached patch allows for shell curly braces with fnmatch.filter().

This makes the following possible:
>>> import fnmatch
>>> import os
>>>
>>> for file in os.listdir('.'):
...     if fnmatch.fnmatch(file, '*.{txt,csv}'):
...         print file
...
file.csv
file.txt
foo.txt

This is especially convenient with the glob module:
>>> import glob
>>> glob.glob('*.{txt,csv}')
['file.csv', 'file.txt', 'foo.txt']

Hopefully, this makes fnmatch match better the behavior that people expect from a shell-style pattern matcher.

Please note: I attached a patch that applies on the Python trunk, but only tested it on Python 2.5 on Windows. However, the fnmatch module doesn't seem to have changed substantially in between.
History
Date User Action Args
2010-08-13 08:36:53bochechasetrecipients: + bochecha
2010-08-13 08:36:53bochechasetmessageid: <1281688613.27.0.00233773234268.issue9584@psf.upfronthosting.co.za>
2010-08-13 08:36:51bochechalinkissue9584 messages
2010-08-13 08:36:49bochechacreate