Re: simple string question

2009-09-08 Thread Scott David Daniels
D'Arcy J.M. Cain wrote: On Mon, 7 Sep 2009 15:29:23 +1000 "jwither" wrote: Given a string (read from a file) which contains raw escape sequences, (specifically, slash n), what is the best way to convert that to a parsed string, where the escape sequence has been replaced (specifically, by a N

Re: simple string question

2009-09-07 Thread Niklas Norrthon
On 8 Sep, 05:39, Steven D'Aprano wrote: > On Mon, 07 Sep 2009 01:54:09 -0700, Niklas Norrthon wrote: > > Others have answered how to replace '\\n' with '\n'. For a more general > > approach which will handle all string escape sequences allowed in python > > (including '\xdd' and similar), python's

Re: simple string question

2009-09-07 Thread jwither
"ryles" wrote in message news:b96be200-9762-4f92-bd0d-9be076bcd...@y20g2000vbk.googlegroups.com... > >> There's probably a more general method covering all the escape >> sequences, but for just \n: >> >> your_string = your_string.replace("\\n", "\n") > > py> s = "hello\\r\\n" > py> s > 'hello\\r

Re: simple string question

2009-09-07 Thread Steven D'Aprano
On Mon, 07 Sep 2009 01:54:09 -0700, Niklas Norrthon wrote: > Others have answered how to replace '\\n' with '\n'. For a more general > approach which will handle all string escape sequences allowed in python > (including '\xdd' and similar), python's eval can be used: eval can do so much more tha

Re: simple string question

2009-09-07 Thread D'Arcy J.M. Cain
On Mon, 7 Sep 2009 15:29:23 +1000 "jwither" wrote: > Given a string (read from a file) which contains raw escape sequences, > (specifically, slash n), what is the best way to convert that to a parsed > string, where the escape sequence has been replaced (specifically, by a > NEWLINE token)? I

Re: simple string question

2009-09-07 Thread Niklas Norrthon
On 7 Sep, 07:29, "jwither" wrote: > Given a string (read from a file) which contains raw escape sequences, > (specifically, slash n), what is the best way to convert that to a parsed > string, where the escape sequence has been replaced (specifically, by a > NEWLINE token)? > > James Withers Othe

Re: simple string question

2009-09-07 Thread ryles
> There's probably a more general method covering all the escape > sequences, but for just \n: > > your_string = your_string.replace("\\n", "\n") py> s = "hello\\r\\n" py> s 'hello\\r\\n' py> s.decode("string_escape") 'hello\r\n' py> -- http://mail.python.org/mailman/listinfo/python-list

Re: simple string question

2009-09-07 Thread jwither
"Chris Rebert" wrote in message news:mailman.1075.1252306208.2854.python-l...@python.org... > On Sun, Sep 6, 2009 at 10:29 PM, jwither wrote: >> Given a string (read from a file) which contains raw escape sequences, >> (specifically, slash n), what is the best way to convert that to a parsed >>

Re: simple string question

2009-09-06 Thread Chris Rebert
On Sun, Sep 6, 2009 at 10:29 PM, jwither wrote: > Given a string (read from a file) which contains raw escape sequences, > (specifically, slash n), what is the best way to convert that to a parsed > string, where the escape sequence has been replaced (specifically, by a > NEWLINE token)? There's p

Re: simple string question

2009-09-06 Thread 7stud
On Sep 6, 11:29 pm, "jwither" wrote: > Given a string (read from a file) which contains raw escape sequences, > (specifically, slash n), what is the best way to convert that to a parsed > string, where the escape sequence has been replaced (specifically, by a > NEWLINE token)? > > James Withers 1

Re: simple string question

2009-09-06 Thread Sean DiZazzo
On Sep 6, 10:29 pm, "jwither" wrote: > Given a string (read from a file) which contains raw escape sequences, > (specifically, slash n), what is the best way to convert that to a parsed > string, where the escape sequence has been replaced (specifically, by a > NEWLINE token)? > > James Withers I

simple string question

2009-09-06 Thread jwither
Given a string (read from a file) which contains raw escape sequences, (specifically, slash n), what is the best way to convert that to a parsed string, where the escape sequence has been replaced (specifically, by a NEWLINE token)? James Withers -- http://mail.python.org/mailman/listinfo/p

Re: a simple string question

2007-07-28 Thread vedrandekovic
On 28 srp, 14:15, Steve Holden <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > On 28 srp, 07:05, Zentrader <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > NEW TEXT : "Hello world;\nHello:\n\t\t\n\n\n\n\n\nHello2" > >> If you are doing all of this to format the output i

Re: a simple string question

2007-07-28 Thread Zentrader
> >>> Short_Text="n=90; if n==90:print 'ok'" > >>> compound_lines = Short_Text.split(";") > >>> for line in compound_lines: > ... line = line.replace(":", ":\n") > ... print line > ... > n=90 > if n==90: > print 'ok' A variation of this will work if the input file isn't too compl

Re: a simple string question

2007-07-28 Thread Steve Holden
[EMAIL PROTECTED] wrote: > On 28 srp, 07:05, Zentrader <[EMAIL PROTECTED]> wrote: [EMAIL PROTECTED] wrote: > NEW TEXT : "Hello world;\nHello:\n\t\t\n\n\n\n\n\nHello2" >> If you are doing all of this to format the output into columns, >> Python's print() or write() will do this, and is eas

Re: a simple string question

2007-07-28 Thread vedrandekovic
On 28 srp, 07:05, Zentrader <[EMAIL PROTECTED]> wrote: > > > [EMAIL PROTECTED] wrote: > > > > NEW TEXT : "Hello world;\nHello:\n\t\t\n\n\n\n\n\nHello2" > > If you are doing all of this to format the output into columns, > Python's print() or write() will do this, and is easier as well. Some > mor

Re: a simple string question

2007-07-27 Thread Zentrader
> > [EMAIL PROTECTED] wrote: > > > NEW TEXT : "Hello world;\nHello:\n\t\t\n\n\n\n\n\nHello2" If you are doing all of this to format the output into columns, Python's print() or write() will do this, and is easier as well. Some more info on what you want to do will clear things up. -- http://ma

Re: a simple string question

2007-07-27 Thread Zentrader
On Jul 27, 11:26 am, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > >> If I understand you correctly you want to replace ";" by ";\n" and ":" > >> by ":\n\t\t\t\t\t\t\t". > >> Well guess what? The replace() method does just this. Have a read: > >> http://docs.python.o

Re: a simple string question

2007-07-27 Thread Wildemar Wildenburger
[EMAIL PROTECTED] wrote: >> If I understand you correctly you want to replace ";" by ";\n" and ":" >> by ":\n\t\t\t\t\t\t\t". >> Well guess what? The replace() method does just this. Have a read: >> http://docs.python.org/lib/string-methods.html> >> > No,that's not what I need... > When this f

Re: a simple string question

2007-07-27 Thread vedrandekovic
On 27 srp, 19:29, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > I have one question about string.I am trying to make an function to > > analyze line of some text, this is my example: "HELLO;HELLO2:WORLD:", > > if that function in this text find ";" and ":" ( in t

Re: a simple string question

2007-07-27 Thread Wildemar Wildenburger
[EMAIL PROTECTED] wrote: > I have one question about string.I am trying to make an function to > analyze line of some text, this is my example: "HELLO;HELLO2:WORLD:", > if that function in this text find ";" and ":" ( in this example will > find both) > > e.g that function must return this: > >

Re: a simple string question

2007-07-27 Thread Zentrader
On Jul 27, 8:23 am, [EMAIL PROTECTED] wrote: > Hello, > > I have one question about string.I am trying to make an function to > analyze line of some text, this is my example: "HELLO;HELLO2:WORLD:", > if that function in this text find ";" and ":" ( in this example will > find both) > > e.g that

a simple string question

2007-07-27 Thread vedrandekovic
Hello, I have one question about string.I am trying to make an function to analyze line of some text, this is my example: "HELLO;HELLO2:WORLD:", if that function in this text find ";" and ":" ( in this example will find both) e.g that function must return this: "HELLO;\nHELLO2:\n\t\t\t\t\t\t