Reading long lines doesn't work in Python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scott Simpson

    #1

    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?
  • jay graves

    #2
    Re: Reading long lines doesn't work in Python

    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"*1 1000 + '\n')
    >>f.write("x"*1 1000 + '\n')
    >>f.write("x"*1 1000 + '\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

    Comment

    • Scott Simpson

      #3
      Re: Reading long lines doesn't work in Python

      Sorry, found the bug somewhere else. You're right. Python is working OK.

      Comment

      Working...