简体   繁体   English

读写模式 Python CSV 文件

[英]Read Write mode Python CSV file

Working on a project, but I wanted read and write mode when I opened the csv file.工作的一个项目,但我想,当我打开CSV文件的读写模式。 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 无法识别它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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