'Straße' ('Strasse') and Python 2
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Mon Jan 13 05:38:03 EST 2014
On Mon, 13 Jan 2014 01:54:21 -0800, wxjmfauth wrote:
>>>> sys.version
> '2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]'
>>>> assert 'Straße'[4] == 'ß'
>>>> assert u'Straße'[4] == u'ß'
I think you are using "from __future__ import unicode_literals".
Otherwise, that cannot happen in Python 2.x. Using a narrow build:
# on my machine "ando"
py> sys.version
'2.7.2 (default, May 18 2012, 18:25:10) \n[GCC 4.1.2 20080704 (Red Hat
4.1.2-52)]'
py> sys.maxunicode
65535
py> assert 'Straße'[4] == 'ß'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError
py> list('Straße')
['S', 't', 'r', 'a', '\xc3', '\x9f', 'e']
Using a wide build is the same:
# on my machine "orac"
>>> sys.maxunicode
1114111
>>> assert 'Straße'[4] == 'ß'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError
But once you run the "from __future__" line, the behaviour changes to
what you show:
py> from __future__ import unicode_literals
py> list('Straße')
[u'S', u't', u'r', u'a', u'\xdf', u'e']
py> assert 'Straße'[4] == 'ß'
py>
But I still don't understand the point you are trying to make.
--
Steven
More information about the Python-list
mailing list