I would also suggest to use the csv module. It is easy to use and fits best if you want to read in table like structures stored in a CSV like format (tab/space/something else delimited).
The module documentation gives good examples where the simplest usage is stated to be:
import csv
with open('/tmp/data.txt', 'r') as f:
reader = csv.reader(f)
for row in reader:
print row
Every row is a list which is very usefull if you want to do index based manipulations.
If you want to change the delimiter there is a keyword for this but I am often fine with the predefined dialects which can also be defined via a keyword.
import csv
with open('/tmp/data.txt', 'r') as f:
reader = csv.reader(f, dialect='excel', delimiter='')
for row in reader:
print row
I am not sure if this will fix your problems but the use of elaborated modules will ensure you that something is wrong with your file and not your code if the error will remain.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…