When I try to open a file in python I get the error, typeerror '_csv.reader' object is not subscriptable. The code is as below, can someone kindly help me please
with open(file) as f:
reader = csv.reader(f, delimiter='\t')
for line in reader:
oldseq, city, state, newseq = line
The error is here, in the following code, for line in reader[:1]:
with open(newfile) as f:
reader = csv.reader(f, delimiter='\t')
for line in reader[:1]:
oldseq, city, state, newseq = line
I need to just skip the first line as it has headers, thats why I was doing reader[:1]
You cannot slice a reader
object; you can skip the first row with:
with open(newfile) as f:
reader = csv.reader(f, delimiter='\t')
next(reader, None) # skip header
for line in reader:
oldseq, city, state, newseq = line
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With