glob & fnmatch unable to match dirs/files containing [ ] ?

Steven Taschuk staschuk at telusplanet.net
Sat Mar 22 15:54:18 EST 2003


Quoth Robert:
  [...]
> quoting attempts don't work:
> 
> >>> glob.glob(  r'testsync\[2\]/*'  )            # or  'testsync\\[2\\]/*'
> []

You can quote the '[' by putting it in a character class of its
own:
	>>> glob.glob('testsync[[]2]')
	['testsync[2]']

-- 
Steven Taschuk                  staschuk at telusplanet.net
"Telekinesis would be worth patenting."  -- James Gleick





More information about the Python-list mailing list