[New-bugs-announce] [issue4573] zsh-style subpattern matching for fnmatch/glob
Erick Tryzelaar
report at bugs.python.org
Sun Dec 7 09:17:57 CET 2008
New submission from Erick Tryzelaar <idadesub at users.sourceforge.net>:
As I mentioned on python-ideas, I my project needs to extend fnmatch to
support zsh-style globbing, where you can use brackets to designate
subexpressions. Say you had a directory structure like this:
foo/
foo.ext1
foo.ext2
bar/
foo.ext1
foo.ext2
The subexpressions will let you do patterns like this:
>>> glob.glob('foo/foo.{ext1,ext2}')
['foo/foo.ext1', 'foo/foo.ext2']
>>> glob.glob('foo/foo.ext{1,2}')
['foo/foo.ext1', 'foo/foo.ext2']
>>> glob.glob('{foo,bar}')
['bar', 'foo']
>>> glob.glob('{foo,bar}/foo*')
['bar/foo.ext1', 'bar/foo.ext2', 'foo/foo.ext1', 'foo/foo.ext2']
>>> glob.glob('{foo,bar}/foo.{ext*}')
['bar/foo.ext1', 'bar/foo.ext2', 'foo/foo.ext1', 'foo/foo.ext2']
>>> glob.glob('{f?o,b?r}/foo.{ext*}')
['bar/foo.ext1', 'bar/foo.ext2', 'foo/foo.ext1', 'foo/foo.ext2']
Would this be interesting to anyone else? It would unfortunately break
fnmatch since it currently treats {} as ordinary characters. It'd be
easy to work around that by adding a flag or using a different function
name though. Anyway, here's the patch against the head of py3k.
----------
components: Library (Lib)
files: zsh-fnmatch.diff
keywords: patch
messages: 77216
nosy: erickt
severity: normal
status: open
title: zsh-style subpattern matching for fnmatch/glob
type: feature request
versions: Python 3.0
Added file: http://bugs.python.org/file12259/zsh-fnmatch.diff
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4573>
_______________________________________
More information about the New-bugs-announce
mailing list