473,386 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Reading long lines doesn't work in Python

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
2 1239
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
Sorry, found the bug somewhere else. You're right. Python is working OK.

Jul 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Matt DeFoor | last post by:
I have some log files that I'm working with that look like this: 1000000000 3456 1234 1000000001 3456 1235 1000020002 3456 1223 1000203044 3456 986 etc. I'm trying to read the file...
11
by: Matt DeFoor | last post by:
I have some log files that I'm working with that look like this: 1000000000 3456 1234 1000000001 3456 1235 1000020002 3456 1223 1000203044 3456 986 etc. I'm trying to read the file...
3
by: Marco Herrn | last post by:
Hi, I have a text file with some lines in it. Now I want to iterate over this file and exchange some lines with some others. I tried this approach: try: myfile= file('myfile', 'r+') while...
25
by: 7stud | last post by:
I can't break out of the for loop in this example: ------ import sys lst = for line in sys.stdin: lst.append(line) break
12
by: WaterWalk | last post by:
Hello. I wonder what's the effective way of figuring out how a piece of python code works. With C I often find it very useful to be able to run the code in step mode and set breakpoints in a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.