On Sun, Sep 9, 2018 at 6:03 PM, Thomas Jollans <t...@tjol.eu> wrote: > On 09/09/2018 02:20 PM, Gilmeh Serda wrote: >> >> >> # Python 3.6.1/Linux >> (acts the same in Python 2.7.3 also, by the way) >> >>>>> from glob import glob >> >> >>>>> glob('./Testfile *') >> >> ['./Testfile [comment] some text.txt'] >> >>>>> glob('./Testfile [comment]*') >> >> [] >> [...] > > https://docs.python.org/3/library/glob.html#glob.escape demonstrates a way > of escaping that works: > > 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 [[]*'). And in the negative case it would provide many false positives. (e.g. "Testfile [falacy]", "Testfile monty", "Testfile ]not quite" and so on) Even if you wanted to use that strange character class, which is not a good idea (as explained above), using "[[]coment]" would be better, since there is no reason to repeat a character. -- https://mail.python.org/mailman/listinfo/python-list