473,385 Members | 1,317 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,385 software developers and data experts.

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

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
0 1170

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

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
0
by: Norm Wong | last post by:
If anyone is interested in using db2uext2 with Cygwin gcc compiler on Windows, I've modified the IBM provided sample with the attached file. There are two main modifications. The mkdir command...
4
by: R Bolling | last post by:
I have a text file from a text document that has very long rows (two or three paragraphs from a text document for each row). Importing to text cuts it off at 255 characters, and importing to a...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
6
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any...
36
by: felixnielsen | last post by:
What i really wanna do, is defining my own types, it doesnt really matter why. Anyway, i have run into some problems 1) typedef unsigned short U16; U16 test = 0xffffffff; // There should be a...
1
by: mike5160 | last post by:
Hi all, My input file looks like this : ( the data is separated by tabs ) 11/26/2007 56.366 898.90 -10.086 23.11 1212.3 11/26/2007 52.25 897.6 -12.5 12.6 13333.5...
5
by: Neil Crighton | last post by:
I'm using the zipfile library to read a zip file in Windows, and it seems to be adding too many newlines to extracted files. I've found that for extracted text-encoded files, removing all instances...
1
by: Joe Strout | last post by:
On Nov 19, 2008, at 3:27 PM, Mohsen Akbari wrote: Appears that way where? Using what tool to view it? My guess is that there is nothing wrong with the file, but that whatever you're using...
0
by: Matthew Barnett | last post by:
Steve Holden wrote: 20 Some text editors can display very long lines, others can't and just wrap them when displaying. Notepad can't.
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.