Re: Escaping certain characters

2005-09-10 Thread Kent Johnson
Jan Danielsson wrote: > Robert Kern wrote: > [---] > >>>Hmm... On second thought, I need to escape more characters. >>> >>>Is there no other way to escape characters in strings? >> >>Which characters? > > >I need to escape '\n', '"', '[' and ']'. I finally went with a few of > these: > strin

Re: Escaping certain characters

2005-07-31 Thread Robert Kern
Jan Danielsson wrote: > Robert Kern wrote: > [---] > >>> I need to escape '\n', '"', '[' and ']'. I finally went with a few of >>>these: >>>string.replace('\n', '\\n') >>>string.replace('"', '\\"') >>>... >>> >>> I assume that's good enough, but I somehow expected there to exist >>>some form o

Re: Escaping certain characters

2005-07-31 Thread Jan Danielsson
Robert Kern wrote: [---] >>I need to escape '\n', '"', '[' and ']'. I finally went with a few of >> these: >> string.replace('\n', '\\n') >> string.replace('"', '\\"') >> ... >> >>I assume that's good enough, but I somehow expected there to exist >> some form of "insert your conversion tabl

Re: Escaping certain characters

2005-07-31 Thread Robert Kern
Jan Danielsson wrote: > Robert Kern wrote: > [---] > >>>Hmm... On second thought, I need to escape more characters. >>> >>>Is there no other way to escape characters in strings? >> >>Which characters? > >I need to escape '\n', '"', '[' and ']'. I finally went with a few of > these: > string.r

Re: Escaping certain characters

2005-07-31 Thread Jan Danielsson
Robert Kern wrote: [---] >> Hmm... On second thought, I need to escape more characters. >> >> Is there no other way to escape characters in strings? > > Which characters? I need to escape '\n', '"', '[' and ']'. I finally went with a few of these: string.replace('\n', '\\n') string.replace('"'

Re: Escaping certain characters

2005-07-31 Thread Robert Kern
Jan Danielsson wrote: > Jan Danielsson wrote: > >>>In [3]: s.encode('string_escape') >>>Out[3]: 'Hello\\nWorld!' >>> >>>In [4]: Out[3].decode('string_escape') >>>Out[4]: 'Hello\nWorld!' >>> >>>Not *quite* what you asked for, but it ought to be close enough. >> >>That'll do just fine. Many thanks!

Re: Escaping certain characters

2005-07-31 Thread Jan Danielsson
Jan Danielsson wrote: >>In [3]: s.encode('string_escape') >>Out[3]: 'Hello\\nWorld!' >> >>In [4]: Out[3].decode('string_escape') >>Out[4]: 'Hello\nWorld!' >> >>Not *quite* what you asked for, but it ought to be close enough. > > That'll do just fine. Many thanks! Hmm... On second thought, I need

Re: Escaping certain characters

2005-07-30 Thread Jan Danielsson
Robert Kern wrote: [---] > In [3]: s.encode('string_escape') > Out[3]: 'Hello\\nWorld!' > > In [4]: Out[3].decode('string_escape') > Out[4]: 'Hello\nWorld!' > > Not *quite* what you asked for, but it ought to be close enough. That'll do just fine. Many thanks! -- http://mail.python.org/mailman/

Re: Escaping certain characters

2005-07-30 Thread Robert Kern
Jan Danielsson wrote: > Hello, > > I'd like to encode the string that outputs: > > Hello > World! > > to 'Hello\x0aWorld!', and the string that outputs: > > Hello\World! > > to 'Hello\\World!'. > > Obviously, I want to be able to reverse the process. > > I'm going to assume this has already