Read Write mode Python CSV file

Viewed 188

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?

1 Answers

Use r+ or a+ or w+ not rw as python doesn't recognise it

Related