Reading long lines doesn't work in Python

jay graves jaywgraves at gmail.com
Wed Jul 19 12:37:00 EDT 2006


Scott Simpson wrote:
> I have a loop
>
> for line in f:
>      ...
>
> and if the line is over about 10,000 characters it lops it off. How do I
> get around this?

Hmmm.  Works for me on Windows.

Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> f = file('longline.txt','w')
>>> f.write("x"*11000 + '\n')
>>> f.write("x"*11000 + '\n')
>>> f.write("x"*11000 + '\n')
>>> f.close()
>>> f = file('longline.txt','r')
>>> for l in f:
...     print len(l)
...
11001
11001
11001
>>> f.close()

Could the file have embedded nulls?  Are you on Windows?  If the file
is small enough, open it in binary mode and do a split on '\n to verify
your data.

...
jay




More information about the Python-list mailing list