簡體   English   中英

讀寫模式 Python CSV 文件

[英]Read Write mode Python CSV file

工作的一個項目,但我想,當我打開CSV文件的讀寫模式。 可悲的是,它給了我一個錯誤。 這是代碼:

import csv

with open("historicalData/ACAD.csv", "rw") as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=',')
    for lines in csv_reader:
      print(lines[0])

我得到的錯誤:

Traceback (most recent call last):
File "c:/Users/sande/Desktop/Vihaan/ThirdPartySoftware/Python/VisualStudiosCode/DadWork/test.py", line 3, in <module>
    with open("historicalData/ACAD.csv", "ra") as csv_file:
ValueError: must have exactly one of create/read/write/append mode

任何人都可以幫助實現這一目標嗎?

使用r+a+w+而不是rw因為 python 無法識別它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM