I have the following code:
import glob
files = ".\database\*.txt"
for pathname in glob.glob(files):
print pathname
I understand in different OS directory are represented differently. So I am wondering is ".\database*.txt" robust across different OS?
I tried
files = "./database/*.txt"
and it also worked.
If I want to make my code robust, what is the best way to do it?
You can ask Python what to use:
In [1]: import os.path
In [2]: os.path.sep
Out[2]: '/'