strip()
already removes the spaces from both ends. The error is in the line:
for x in eachLine.split(' '):
You should use line
and not eachLine
in the for
.
To avoid this kind of problems you could avoid using the intermediate variable at all:
for line in f:
for x in line.strip().split():
# do stuff
Note that calling split()
without arguments splits on any sequence of whitespace, which is usually what you want. See:
>>> 'a b c d'.split()
['a', 'b', 'c', 'd']
>>> 'a b c d'.split(' ')
['a', '', 'b', 'c', 'd']
Note the empty string of the last result. split(' ')
splits on every single whitespace.