Re: simple string question

2009-09-08 Thread Niklas Norrthon
On 8 Sep, 05:39, Steven D'Aprano ste...@remove.this.cybersource.com.au 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

Re: simple string question

2009-09-07 Thread Sean DiZazzo
On Sep 6, 10:29 pm, jwither jwit...@sxder4kmju.com 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)?

Re: simple string question

2009-09-07 Thread 7stud
On Sep 6, 11:29 pm, jwither jwit...@sxder4kmju.com 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)?

Re: simple string question

2009-09-07 Thread Chris Rebert
On Sun, Sep 6, 2009 at 10:29 PM, jwitherjwit...@sxder4kmju.com 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

Re: simple string question

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

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 Niklas Norrthon
On 7 Sep, 07:29, jwither jwit...@sxder4kmju.com 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)?

Re: simple string question

2009-09-07 Thread D'Arcy J.M. Cain
On Mon, 7 Sep 2009 15:29:23 +1000 jwither jwit...@sxder4kmju.com 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

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 than

Re: simple string question

2009-09-07 Thread jwither
ryles ryle...@gmail.com 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\\n'