python excel/csvファイルの読み書き
644 ワード
os.path.split():ファイル名とパスをパス別に分割
eg
# PATH :
# ,
# ,
os.path.split('PATH')
eg
file_dir, file_name = os.path.split(file_path)
os.chdir(file_dir)
# excel list
data = xlrd.open_workbook(file_name)
table = data.sheets()[0]
xls_list = []
for i in range(table.nrows):
xls_list.append(table.row_values(i))
# list csv
zip_file_name = 'test.csv'
with open(zip_file_name, 'w', encoding='utf8') as csv_file:
writer = csv.writer(csv_file)
writer.writerows(xls_list)