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


Groups > comp.lang.python > #17589 > unrolled thread

Re: Performing a number of substitutions on a unicode string

Started byArnaud Delobelle <arnodel@gmail.com>
First post2011-12-20 17:04 +0000
Last post2011-12-20 17:04 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#17589 — Re: Performing a number of substitutions on a unicode string

FromArnaud Delobelle <arnodel@gmail.com>
Date2011-12-20 17:04 +0000
SubjectRe: Performing a number of substitutions on a unicode string
Message-ID<mailman.3869.1324400691.27778.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web