Open file knowing only a part of its name

后端 未结 4 945
轻奢々
轻奢々 2021-01-05 04:52

I\'m currently reading a file and importing the data in it with the line:

# Read data from file.
data = np.loadtxt(join(mypath, \'file.data\'), unpack=True)
         


        
4条回答
  •  旧巷少年郎
    2021-01-05 05:37

    I simple solution would be to use the python modules "os" and "re":

    import os
    import re
    for file in os.listdir(mypath):
         if re.match("file_\d+\.data", file):
         ...
    

提交回复
热议问题