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

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

P: n/a
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)
'0.0\t3.0\t10.0\t24.0\t30.0\t30.0\t30.0\t30.0\t30. 0\t30.0\t30.0\t30.0\t30.0\t30.0\t30.0\t30.0\t30.0\ t30.0\t30.0\t30.0\t30.0\t30.0\t33.0\t40.0\t40.0\t4 0.0\t40.0\t32.0\t30.0\t32.0\t26.0\t23.0\t30.0\t32. 0\t40.0\t40.0\t40.0\t40.0\t40.0\t40.0\t38.0\t30.0\ t30.0\t30.0\t30.0\t30.0\t30.0\t30.0\t24.0\t10.0\t1 1.0\t20.0\t20.0\t20.0\t20.0\t20.0\t20.0\t18.0\t10. 0\t10.0\t10.0\t10.0\t10.0\t10.0\t17.0\t20.0\t23.0\ t30.0\t30.0\t30.0\t27.0\t20.0\t20.0\t30.0\t30.0\t3 0.0\t30.0\t30.0\t30.0\t30.0\t30.0\t30.0\t30.0\t30. 0\t30.0\t30.0\t30.0\t30.0\t30.0\t23.0\t20.0\t20.0\ t20.0\t20.0\t10.0\t10.0\t14.0\t20.0\t20.0\t20.0\t2 0.0\t20.0\t20.0\t20.0\t20.0\t20.0\t20.0\t20.0\t27. 0\t30.0\t30.0\t27.0\t20.0\t20.0\t20.0\t20.0\t20.0\ t20.0\t20.0\t20.0\t19.0\t10.0\t10.0\t10.0\t10.0\t1 0.0\t10.0\t12.0\t10.0\t13.0\t13.0\t10.0\t2.0\t0.0\ t3.0\t5.0\t10.0\t5.0\t10.0\t10.0\t10.0\t10.0\t10.0 \t10.0\t10.0\t10.0\t5.0\t0.0\t2.0\t10.0\t10.0\t10. 0\t10.0\t10.0\t10.0\t10.0\t10.0\t10.0\t10.0\t10.0\ t10.0\t10.0\t10.0\t10.0\t10.0\t16.0\t20
..0\t20.0\t20.0\t20.0\t20.0\t20.0\t20.0\t20.0\t20. 0\t10.0\t18.0\t20.0\t20.0\t20.0\t20.0\t20.0\t20.0\ t27.0\t30.0\t30.0\t35.0\t40.0\t40.0\t31.0\t20.0\t2 0.0\t21.0\t30.0\t33.0\t46.0\t50.0\t50.0\t50.0\t48. 0\t40.0\t43.0\t50.0\t50.0\t50.0\t56.0\t60.0\t60.0\ t60.0\t61.0\t70.0\t70.0\t70.0\t70.0\t75.0\t80.0\t8 3.0\t90.0\t90.0\t92.0\t100.0\t100.0\t100.0\t100.0\ t100.0\t100.0\t93.0\t86.0\t80.0\t91.0\t100.0\t100. 0\t100.0\t100.0\t98.0\t90.0\t90.0\t90.0\t94.0\t100 .0\t100.0\t100.0\t100.0\t100.0\t100.0\t100.0\t100. 0\t100.0\t100.0\t100.0\t100.0\t100.0\t100.0\t100.0 \t100.0\t100.0\t100.0\t100.0\t100.0\t100.0\t100.0\ t100.0\t90.0\t83.0\t87.0\t90.0\t90.0\t90.0\t90.0\t 90.0\t90.0\t90.0\t90.0\t90.0\t90.0\t90.0\t90.0\t90 .0\t90.0\t90.0\t90.0\t90.0\t90.0\t90.0\t90.0\t90.0 \t90.0\t90.0\t90.0\t90.0\t90.0\t90.0\t90.0\t90.0\t 90.0\t90.0\t90.0\t90.0\t90.0\t90.0\t90.0\t'
>
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).

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

Nov 20 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.