Formatting string with accented characters for printing

wxjmfauth at gmail.com wxjmfauth at gmail.com
Mon Jan 26 09:31:26 EST 2015


Le dimanche 18 janvier 2015 19:29:12 UTC+1, Peter Otten a écrit :
> 
> The best approach is to convert your data to unicode as soon as you read it 
> and perform all string operations with unicode. This also avoids breaking 
> characters:
> 
> >>> print "Méresse"[:2]
> M�                                                                                                                                                    
> >>> print u"Méresse"[:2]
>> 
> There are still problems (e. g. with narrow builds), and the best way to 
> avoid a few string-related inconviences is to switch to Python 3.

Well,

>>> print 'Méresse'
Méresse
>>> print u'Méresse'
Méresse
>>> print 'Méresse'[:2]
Mé
>>> print u'Méresse'[:2]
Mé
>>> sys.version
'2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]'
>>>

jmf



More information about the Python-list mailing list