I'm reading the file, so how do I get the turns, or index for each line?
for line in excelRead:
keywrds=[]
title=line.split("+")
title=[lines.strip()for lines in title]
print title[0]
So, when I read my first line in excel, line variable is equal to line value in excel, but how do I find which turn it is?
Use enumerate()
:
for index, line in enumerate(excelRead, start=1):
keywrds=[]
title=line.split("+")
title=[lines.strip()for lines in title]
print title[0]
print index
The start
parameter to the enumerate
indicates that you want to start the index at 1, instead of 0.
Try:
for index, line in enumerate(excelRead, start=1):
# use index as you wish
keywrds=[]
title=line.split("+")
title=[lines.strip()for lines in title]
print title[0]
start=1
because by default it starts at 0
, but Excel's first row is row 1
.
You can find out more about the built-in enumerate
function here.
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