Re: Escaping certain characters
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.replace('\n', '\\n') string.replace('', '\\') You might like this recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81330 Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: Escaping certain characters
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 to escape more characters. Is there no other way to escape characters in strings? -- http://mail.python.org/mailman/listinfo/python-list
Re: Escaping certain characters
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! Hmm... On second thought, I need to escape more characters. Is there no other way to escape characters in strings? Which characters? -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: Escaping certain characters
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.replace('\n', '\\n') string.replace('', '\\') ... I assume that's good enough, but I somehow expected there to exist some form of insert your conversion table here built-in string escaper. Write a codec. -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: Escaping certain characters
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 table here built-in string escaper. Write a codec. Is that what string.encode() uses? Some behind-the-scenes codec? I tried searching for it, but could only find UTF/Unicode-related information. Is it in the normal python documentation? Semi-Offtopic: The search facility in the Python help has stopped functioning for me (I'm using XP on this system). No matter what I search for, I get no results. A week ago, I got a lot of hits for almost anything I searched for. Anyone seen this behavior, and knows what to do about it? -- Kind Regards, Jan Danielsson Te audire no possum. Musa sapientum fixa est in aure. -- http://mail.python.org/mailman/listinfo/python-list
Re: Escaping certain characters
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 of insert your conversion table here built-in string escaper. Write a codec. Is that what string.encode() uses? Some behind-the-scenes codec? I tried searching for it, but could only find UTF/Unicode-related information. Is it in the normal python documentation? Semi-Offtopic: The search facility in the Python help has stopped functioning for me (I'm using XP on this system). No matter what I search for, I get no results. A week ago, I got a lot of hits for almost anything I searched for. Anyone seen this behavior, and knows what to do about it? Use Google: site:docs.python.org codecs -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Escaping certain characters
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 been solved in Python.. But how? -- http://mail.python.org/mailman/listinfo/python-list
Re: Escaping certain characters
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/listinfo/python-list