python 2.7 lowercase python 2.7 lowercase python python

python 2.7 lowercase


Use unicode strings:

drostie@signy:~$ pythonPython 2.7.2+ (default, Oct  4 2011, 20:06:09) [GCC 4.6.1] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> print "ŠČŽ"ŠČŽ>>> print "ŠČŽ".lower()ŠČŽ>>> print u"ŠČŽ".lower()ščž

See that little u? That means that it's created as a unicode object rather than a str object.


Use unicode:

>>> print u'ŠČŽ'.lower().encode('utf8')ščž>>>

You need to convert your text to unicode as soon as it enters your programme from the outside world, rather than merely at the point at which you notice an issue.

Accordingly, either use the codecs module to read in decoded text, or use 'bytestring'.decode('latin2') (where in place of latin2 you should use whatever the actual encoding is).