1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import csv
file = list (csv.reader( open ( 'Books2.csv' )))
tmp = []
for row in file :
tmp.append(row)
x = 0
for row in tmp:
print (x,tmp[x])
x = x + 1
remove = int ( input ( 'Which row would you like to remove from the list?' ))
del tmp[remove]
x = 0
for row in file :
print (x,tmp[x])
x = x + 1
change = int ( input ( 'Which row would you like to change?' )
for row in file :
if tmp[z] = = change:
book = input ( 'Please enter the title of a book' )
author = input ( 'Please enter the name of the author' )
year = input ( 'Please enter the year the book was released' )
new_entry = book + ',' + author + ',' + year + '\n'
tmp[z] = str (new_entry)
file = open ( 'Books2.csv' , 'w' )
y = 0
for row in tmp:
file .write( str (tmp[y]) + '\n' )
y = y + 1
file .close
|
This code gives me the following error and I'm not sure why, can anyone offer any help or advice?
Error:
line 23
for row in file:
^
SyntaxError: invalid syntax
Thanks