Re: Performing a number of substitutions on a unicode string

2011-12-20 Thread Arnaud Delobelle
On 20 December 2011 15:35, Peter Otten <__pete...@web.de> wrote: escape_map = { > ...     u'\n': u'\\n', > ...     u'\t': u'\\t', > ...     u'\r': u'\\r', > ...     u'\f': u'\\f', > ...     u'\\': u'' > ... } escape_map = dict((ord(k), v) for k, v in escape_map.items()) print u"

Re: Performing a number of substitutions on a unicode string

2011-12-20 Thread Peter Otten
Arnaud Delobelle wrote: > I've got to escape some unicode text according to the following map: > > escape_map = { > u'\n': u'\\n', > u'\t': u'\\t', > u'\r': u'\\r', > u'\f': u'\\f', > u'\\': u'' > } > > The simplest solution is to use str.replace: > > def escape_text(tex

Re: Performing a number of substitutions on a unicode string

2011-12-20 Thread Arnaud Delobelle
On 20 December 2011 14:54, Tim Chase wrote: > On 12/20/11 08:02, Arnaud Delobelle wrote: >> >> Hi all, >> >> I've got to escape some unicode text according to the following map: >> >> escape_map = { >>     u'\n': u'\\n', >>     u'\t': u'\\t', >>     u'\r': u'\\r', >>     u'\f': u'\\f', >>     u'\\

Re: Performing a number of substitutions on a unicode string

2011-12-20 Thread Tim Chase
On 12/20/11 08:02, Arnaud Delobelle wrote: Hi all, I've got to escape some unicode text according to the following map: escape_map = { u'\n': u'\\n', u'\t': u'\\t', u'\r': u'\\r', u'\f': u'\\f', u'\\': u'' } The simplest solution is to use str.replace: def escape_

Performing a number of substitutions on a unicode string

2011-12-20 Thread Arnaud Delobelle
Hi all, I've got to escape some unicode text according to the following map: escape_map = { u'\n': u'\\n', u'\t': u'\\t', u'\r': u'\\r', u'\f': u'\\f', u'\\': u'' } The simplest solution is to use str.replace: def escape_text(text): return text.replace('\\', '').