[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


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)
'['