-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