My program reads a field like *ABC* and tries to convert it into a glob statement.
I am having issues when trying to restrict the data.
Glob doesn’t work the same in linux bash vs python glob library:
From bash:
bash_level$ ls *FOO*V7*
baz_FOO_V7.txt baz_FOO_V777.txt
bash_level$ ls *FOO*V7[![:digit:]]*
baz_FOO_V7.txt
From ipython:
In [1]: import glob
In [2]: glob.glob("*FOO*V7*.txt")
Out[2]: ['baz_FOO_V7.txt', 'baz_FOO_V777.txt']
In [3]: glob.glob("*FOO*V7[![:digit:]]*.txt")
Out[3]: []
Bottom line:
Out[3] hasn’t the same expected output.
How can I overcome this issue?
Many thanks
You could translate your glob expression into a regular expression:
Of course, at this point you no longer need
globas you could useos.listdir()instead.EDIT
Reading the docs for
globand fnmatch (which is what glob uses to do matching), it appears that your match could be written as:as well.