Message113750
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. |
|
Date |
User |
Action |
Args |
2010-08-13 08:36:53 | bochecha | set | recipients:
+ bochecha |
2010-08-13 08:36:53 | bochecha | set | messageid: <1281688613.27.0.00233773234268.issue9584@psf.upfronthosting.co.za> |
2010-08-13 08:36:51 | bochecha | link | issue9584 messages |
2010-08-13 08:36:49 | bochecha | create | |
|