-1
我有x个目录,它们是Star_ {v},v = 0到x。 我在每个目录中有2个csv文件,一个带有“epoch”一词,一个没有。 如果其中一个csv文件有单词“epoch”,它需要通过一组代码发送,否则通过另一个。 我觉得字典是可能的路要走,但此部分代码是有点错乱如何从python中的多个目录中分别读取多个文件
directory_dict={}
for var in range(0, len(subdirectory)):
#var refers to the number by which the subdirectories are labelled by Star_0, Star_1 etc.
directory_dict['Star_{v}'.format(v=var)]=directory\\Star_{var}
#directory_dict['Star_0'], directory_dict['Star_1'] etc.
read_csv(f) for f in os.listdir('directory_dict[Star_{var}') if f.endswith(".csv")
#reads in all the files in the directories(star{v}) ending in csv.
if 'epoch' in open(read_csv[0]).read():
#if the word epoch is in the csv file then it is
directory_dict[Star_{var}][read] = csv.reader(read_csv[0])
directory_dict[Star_{var}][read1] = csv.reader(read_csv[1])
else:
directory_dict[Star_{var}][read] = csv.reader(read_csv[1])
directory_dict[Star_{var}][read1] = csv.reader(read_csv[0])
除了发布无效Python代码的事实之外,这个问题中没有任何问题。 – davidism 2014-12-02 14:58:10