Re: 'Straße' ('Strasse') and Python 2

wxjmfauth at gmail.com wxjmfauth at gmail.com
Mon Jan 13 04:54:21 EST 2014


Le lundi 13 janvier 2014 09:27:46 UTC+1, Thomas Rachel a écrit :
> Am 12.01.2014 08:50 schrieb wxjmfauth at gmail.com:
> 
> >>>> sys.version
> 
> > 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]
> 
> >>>> s = 'Stra�e'
> 
> >>>> assert len(s) == 6
> 
> >>>> assert s[5] == 'e'
> 
> >>>>
> 
> 
> 
> Wow. You just found one of the major differences between Python 2 and 3.
> 
> 
> 
> Your assertins are just wrong, as s = 'Stra�e' leads - provided you use 
> 
> UTF8 - to a representation of 'Stra\xc3\x9fe', obviously leading to a 
> 
> length of 7.
> 
> 


Not at all. I'm afraid I'm understanding Python (on this
aspect very well).

Do you belong to this group of people who are naively
writing wrong Python code (usually not properly working)
during more than a decade?

'ß' is the the fourth character in that text "Straße"
(base index 0).

This assertions are correct (byte string and unicode).

>>> 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'ß'
>>> 

jmf

PS Nothing to do with Py2/Py3.



More information about the Python-list mailing list