Fwd: Problem with writing a long line in a text file

Steve Holden steve at holdenweb.com
Thu Nov 20 21:21:22 CET 2008

Mohsen Akbari wrote:
> Dear guys,
> I'm a newbie in python and I have this problem with the code that I'm
> writing. There is a very long line which I wish to output it to a text
> file.But when I do this, in the output file, the result appears in two
> lines. I thought maybe that's because the maximum possible length of the
> text file has been reached so I opened the file and I tried to put some
> space at the end of the first line. It wasn't possible to do that for
> the first line and the space was placed before the first character of
> the second line. I kept pressing space bar to add more spaces and so the
> whole second line was moved to the write till it exceeded the first
> line. I mean the length of the second line became longer than the first
> line which means the text file can accept longer lines.
> As a second guess, I thought maybe I had '\n' somewhere in my input
> string so I tried to check that by doing:
>     temp_ =  out_string.find('\n')
>     print temp_
> The result was  -1 which I think means there is not '\n' in my output
> string. Now I'm really confused and I don't know what to do. I really
> appreciate it if somebody can help me out.
> BTW, I'm using windows.
Then, later:
> --- I use notepad to view my txt file. It appears that way in this tool.
> --- Here is the output of the debug lines that you mentioned:
> print *line*.find('\n')
> -1
> print len(*line*)
> 1528
> print repr(line)
> thanks
> Mohsen
There is only one line in your file. Notepad just can't display lines
beyond a certain length, is all, so it inserts a line break in the
window (but not in the file).

Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/

More information about the Python-list mailing list