473,386 Members | 1,598 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.

new line

Dear friends
I'm so sorry to bore you with this trivial problem. Allthou: I have string
having 0x0a as new line, but I should have \n instead.
How should I solve it?
I've tried
text_new=tex_old.replace(str(0x0a), '\n')

and other things, but none of them worked.
Thanks in advance
Aug 29 '05 #1
5 2103
"Kuljo" <ku***@freemail.hu> schrieb im Newsbeitrag
news:K1*******************@nntpserver.swip.net...
Dear friends
I'm so sorry to bore you with this trivial problem. Allthou: I have string
having 0x0a as new line, but I should have \n instead.
How should I solve it?
I've tried
text_new=tex_old.replace(str(0x0a), '\n')

and other things, but none of them worked.
Thanks in advance


text_new=tex_old.replace(chr(0x0a), '\r\n')
works for me.

Claudio
P.S. str(0x0a) == '10'
Aug 29 '05 #2
Kuljo wrote:
Dear friends
I'm so sorry to bore you with this trivial problem. Allthou: I have string
having 0x0a as new line, but I should have \n instead.


In [9]: '\x0a'
Out[9]: '\n'

They're the same thing.

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Aug 29 '05 #3
Kuljo wrote:
Dear friends
I'm so sorry to bore you with this trivial problem. Allthou: I have string
having 0x0a as new line, but I should have \n instead.
How should I solve it?
I've tried
text_new=tex_old.replace(str(0x0a), '\n') and other things, but none of them worked.
Thanks in advance

I have found this in the meantime:
nl="\\"+"n"
text_new=replace(text_old, chr(10), nl)


It works.
Aug 30 '05 #4
Kuljo wrote:
Kuljo wrote:
I'm so sorry to bore you with this trivial problem. Allthou: I have string
having 0x0a as new line, but I should have \n instead.
I have found this in the meantime:nl="\\"+"n"
Note: this is unnecessary. You could just do nl='\\n' instead, and you
don't need the variable "nl" either, which by the way is confusingly
named. Your variable "nl" is actually bound to the two character
sequence \ followed by n instead of a "newline". Is that really what
you wanted?
text_new=replace(text_old, chr(10), nl)
This use of replace() is deprecated. Use text_old.replace() instead.
It works.


For some definitions of "works". This only works if you wanted the
*single* character represented by '\x0a' to turn into the *two*
characters backslash-followed-by-letter-n. The following you might find
instructive:
old = 'some\x0atext'
old 'some\ntext' print old some
text old.encode('string-escape') 'some\\ntext' print old.encode('string-escape')

some\ntext

This will turn other control characters into their equivalent
two-character escaped representation as well, such as \t and \r, as
necessary.

-Peter
Aug 30 '05 #5
Kuljo wrote:
Kuljo wrote:
Dear friends
I'm so sorry to bore you with this trivial problem. Allthou: I have
string having 0x0a as new line, but I should have \n instead.
How should I solve it?
I've tried
>text_new=tex_old.replace(str(0x0a), '\n')

and other things, but none of them worked.
Thanks in advance

I have found this in the meantime:
nl="\\"+"n"
text_new=replace(text_old, chr(10), nl)
It works.


Thanks Peter,
you are right, even
text_new=replace(text_old, chr(10), "\\n")

works.
Yes, it was exactly what I needed. The problem actually was: I'm using Pilot
V for years and a part of my "knowledge base" is stored in den memo files.
On the PC side I'm using jpilot (Linux Kubuntu 5.04) which works perfectly.
Now I wanted to try out kontact (groupware). The shortcoming is that
kontact (actually kpilot in the background) does not import the memos. But
it store them in a folder as a file per memo. In this file are the cr/lf
indicated by hex 0a. The notes in kontact uses char \n instead. For this
translation I made a python script which works now.
Kind regards Kuljo
Aug 31 '05 #6

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

Similar topics

8
by: Peter A. Schott | last post by:
Per subject - I realize I can copy/paste a line at a time into an interactive session when I'm trying to debug, but was wondering if there is any tool out there that allows me to copy sections of...
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
22
by: DraguVaso | last post by:
Hi, For my application I need the following behavior: When I press F4 the cursor has to move to the next line in my multiline textbox which begins with "0". Finding lines starting with 0 isn't...
3
by: Double Echo | last post by:
Hi all, I'm using PHP 4.4.2, and use PHP on both the command-line and the web. I am running PHP on SuSE 10 Linux , in a VMware 5.5 workstation, using Apache 2.0.55 , on my Dell laptop. ...
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
6
by: magix | last post by:
Hi, when I read entries in file i.e text file, how can I determine the first line and the last line ? I know the first line of entry can be filtered using counter, but how about the last line...
6
by: Jacob Rael | last post by:
Hello, I have a simple script to parse a text file (a visual basic program) and convert key parts to tcl. Since I am only working on specific sections and I need it quick, I decided not to...
14
by: WStoreyII | last post by:
the following code is supposed to read a whole line upto a new line char from a file. however it does not work. it is producing weird results. please help. I had error checking in there for...
11
by: xdevel | last post by:
Hi, I don't understand option. if I write: #line 100 "file" I change file numeration to start to line 100 but what "file" ? any example?
19
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
This is an example of the data; 2007/07/27 11:00:03 ARES_INDICATION 010.050.016.002 404.2.01 (6511) RX 74 bytes 2007/07/27 11:00:03 65 11 26 02 BC 6C AA 20 76 93 51 53 50 76 13 48...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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,...

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.