简体   繁体   中英

Read Write mode Python CSV file

Working on a project, but I wanted read and write mode when I opened the csv file. Sadly, it is giving me an error. Here is the code:

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])

And the error I am getting:

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

Can anyone help in how to achieve this?

使用r+a+w+而不是rw因为 python 无法识别它

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM