I am reading a text file which I know its 38th line is “Uncalibrated Peaks:”, and I know its stored in 38th element of my list. I already check them and there is no indexing problem.
I am reading the text file by the following code
import os
fd = open('Report.txt')
contents = fd.readlines()
fd.close()
for ind, line in enumerate(contents):
line = line.split(" ")
contents[ind] = line
but we I check for instance length of first word in the 38th line by
print len(contents[38][0])
25, I know that this command is mention to the correct element in the list, so there is no indexing issue
print len('Uncalibrated')
12
!! although in theory their should be same. seems each character takes 2 place in the string vector, which seems is beause of unicodeing issue
Generally, if it seems like the characters in a string are “too wide”, you probably have a unicode file. Try converting it using the
unicodefunction.Looking at your code above it looks more like a simple indexing error though.