I would like to open a file located in the directory a/b/foldername_12345678 using genfromtxt. The following works for me
file = np.genfromtxt("a/b/foldername_12345678/filename")
However, I don’t want to keep track of the numbers at the end of the directory path in which the file is located (they are uniquely associated with "foldername"). In other words, I would like to open the file without specifying the full directory path. In linux, I can do this via e.g.
cat a/b/foldername*/filename
How can I do the same with genfromtxt?
>Solution :
You can use wildcards with the glob library.
import numpy as np
import glob
filepath = glob.glob("a/b/foldername*/filename")[0]
file = np.genfromtxt(filepath)
The 0 indexing assumes that there is only one possible file that will be found using this wildcard.