By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,444 Members | 1,634 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,444 IT Pros & Developers. It's quick & easy.

Reading long lines doesn't work in Python

P: n/a
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?
Jul 19 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Jul 19 '06 #2

P: n/a
Sorry, found the bug somewhere else. You're right. Python is working OK.

Jul 19 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.