0
私はPythonの初心者ですので、以下の基本的なコードと問題は許してください。取得しています。ここでIOError:[Errno 2] Pythonでファイルを開こうとしているファイルやディレクトリがありません
は私がしようとしているものです:
- ループの特定のフォルダから、指定したフォルダ
- の各CSVファイルはここ
計算を実行
import os import csv def get_all_files(directory): dir_list = os.listdir(directory) csv_files = [] for e in dir_list: if e.endswith('.csv'): csv_files.append(e) return csv_files def sum_from_csv(csv_file): cr = csv.reader(open(csv_file, 'r')) cr.next() file_content=cr.readlines() #initialize throughput total as zero throughput_total=0 #array to save throughput in every iteration throughput_dataset=[] for line in file_content: line=line.strip() data=line.split(",")[1] float_data=float(data) throughput_total+=float_data throughput_dataset.append(float_data) #to calculate number of dataset dataset_length=len(throughput_dataset) throughput_average=throughput_total/dataset_length throughput.append(throughput_average) print "Throughput-total is",throughput_total print "Average is",throughput_average csv_files = get_all_files('/home/gwthamy/Desktop/MyProject/siddhi-benchmarks/filter-4.0.0-M20/filtered-results-filter-4.0.0-M20') for each in csv_files: sum_from_csv(each)
ここに私が得るエラーがあります:
IOError: [Errno 2] No such file or directory: 'output-0-1502441456439.csv'
私はフォルダとファイルが存在することを確認しました。 IOErrorの原因と解決方法また、私のコードには、タスク全体を実行することを妨げる何か他の問題がありますか?
ありがとうございます。
Pythonでパスを表すために 'raw'文字列を使用することをお勧めします。 – godaygo