I am trying to access list element from the token variable, but I keep on getting the error
print token[0]
IndexError: list index out of range'
When I try to access the element from token list.
The contents of the file rebase file are:
ZraI 3 GAC'GTC 0 ! AatII >INV
;ZrmI 3 AGT'ACT 0 ! ScaI,AssI,BmcAI >I
and the code is:
with open (rebase_file, 'r') as rebase:
lines = rebase.readlines()
string = ''
for line in lines:
token = line.split()
print token[0]
You encountered an empty line:
Simply test for this with
if line.strip()::Note that I loop over the file directly instead of reading it all into memory in one go as well.