[英]reading and writing tabular text files in python3
我在一個文件夾中有幾個表格文本文件。第一列中的數據是字符串,第二列和第三列整數。如何將它們全部讀取,並將第一列和第二列編輯后的內容(例如被二除)寫入一個新的表格文本文件? 我剛剛開始學習python,因此請盡可能給出示例代碼。
該代碼段可能會給您一些想法
# terrible code for educational purposes only!
in_stream = open(filename_in)
out_stream = open(filename_out, 'w')
output = csv.writer(out_stream)
for col_string, col_value1, col_value2 in csv.reader(in_stream):
new_row = [col_string, col_value1 / 2, col_value2]
output.write(new_row)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.