new line

K

Kuljo

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 and other things, but none of them worked.
Thanks in advance
 
R

Robert Kern

Kuljo said:
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
(e-mail address removed)

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

Claudio Grondi

Kuljo said:
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
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'
 
K

Kuljo

Kuljo said:
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
and other things, but none of them worked.
Thanks in advance


I have found this in the meantime:

It works.
 
P

Peter Hansen

I have found this in the meantime:

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?

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:
some
text
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
 
K

Kuljo

Kuljo said:
I have found this in the meantime:


It works.

Thanks Peter,
you are right, evenworks.
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,318
Members
47,998
Latest member
GretaCjy4

Latest Threads

Top