i have a syntax error with the with statement. i cant figure it out. i am using python 3 and every time i use the with statement it just wont have it. i am trying to make a reader for a txt file and i need this with statement.
import csv
value1 = "Spam"
fname = input(open("Please enter the name of the file you wish to open: ")
with open(fname, 'rb') as csvfile:
spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
for row in spamreader:
if value1 in row:
print(" ".join(row))
i am very new to python its probably very obvious cheers for the help guys
open(fname, 'r', newline='')instead ofopen(fname, 'rb')(which is how you did it in Python 2.) See the docs.