"glob.glob('weirdness')" Any thoughts?

Peter Otten __peter__ at web.de
Mon Sep 10 09:44:03 EDT 2018


Max Zettlmeißl via Python-list wrote:

>> glob('./Testfile [[]comment]*')
>>
> 
> That is about the least correct working solution one could conceive.
> Of course your suggested "glob('./Testfile [[]comment]*')" works in
> the positive case, but pretty much comes down to a glob('./Testfile
> [[]*').
> 

If you know regular expressions there is an easy way to verify that you are 
wrong:

>>> import fnmatch
>>> fnmatch.translate("foo [[]bar]*")
'foo\\ [[]bar\\].*\\Z(?ms)'

And if you don't:

>>> re.compile(_, re.DEBUG)
literal 102
literal 111
literal 111
literal 32
literal 91
literal 98
literal 97
literal 114
literal 93
max_repeat 0 4294967295
  any None
at at_end_string
re.compile('foo\\ [[]bar\\].*\\Z(?ms)', re.MULTILINE|re.DOTALL|re.DEBUG)
>>> chr(91)
'['





More information about the Python-list mailing list