[issue9584] Allow curly braces in fnmatch
Mathieu Bridon
report at bugs.python.org
Fri Aug 13 10:36:53 CEST 2010
New submission from Mathieu Bridon <bochecha at fedoraproject.org>:
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.
----------
components: Library (Lib)
files: curly-fnmatch.patch
keywords: patch
messages: 113750
nosy: bochecha
priority: normal
severity: normal
status: open
title: Allow curly braces in fnmatch
type: feature request
Added file: http://bugs.python.org/file18497/curly-fnmatch.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9584>
_______________________________________
More information about the Python-bugs-list
mailing list