Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17589

Re: Performing a number of substitutions on a unicode string

References <CAJ6cK1bEzksm9A+nGQP2oPN4-HU6S72nmyQWWzhr=y0CJ=c8QQ@mail.gmail.com> <jcq9v0$o8f$1@dough.gmane.org>
Date 2011-12-20 17:04 +0000
Subject Re: Performing a number of substitutions on a unicode string
From Arnaud Delobelle <arnodel@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3869.1324400691.27778.python-list@python.org> (permalink)

Show all headers | View raw


On 20 December 2011 15:35, Peter Otten <__peter__@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"the quick\n brown\tfox
> jumps\\over\\the\\lazy\\dog".translate(escape_map)
> the quick\n brown\tfox jumps\\over\\the\\lazy\\dog

Thanks.  I think I've got a blind spot about unicode.translate.
Actually, I know why: it's not properly documented where I look [1].

-- 
Arnaud

[1] http://docs.python.org/library/stdtypes.html#str.translate

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Performing a number of substitutions on a unicode string Arnaud Delobelle <arnodel@gmail.com> - 2011-12-20 17:04 +0000

csiph-web