A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/1999-November/001183.html below:

[Python-Dev] Unicode proposal: %-formatting ?

[Python-Dev] Unicode proposal: %-formatting ? [Python-Dev] Unicode proposal: %-formatting ?M.-A. Lemburg mal@lemburg.com
Thu, 11 Nov 1999 16:59:21 +0100
I wonder how we could add %-formatting to Unicode strings without
duplicating the PyString_Format() logic.

First, do we need Unicode object %-formatting at all ?

Second, here is an emulation using strings and <default encoding>
that should give an idea of one could work with the different
encodings:

    s = '%s %i abcäöü' # a Latin-1 encoded string
    t = (u,3)

    # Convert Latin-1 s to a <default encoding> string via Unicode
    s1 = unicode(s,'latin-1').encode()

    # The '%s' will now add u in <default encoding>
    s2 = s1 % t

    # Finally, convert the <default encoding> encoded string to Unicode
    u1 = unicode(s2)

Note that .encode() defaults to the current setting of
<default encoding>.

Provided u maps to Latin-1, an alternative would be:

    u1 = unicode('%s %i abcäöü' % (u.encode('latin-1'),3), 'latin-1')

-- 
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                    50 days left
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/





RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4