New submission from Mathieu Bridon <boche...@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue9584>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to