Unicoding in Python

With Django sub forum.
Post Reply
KBleivik
Site Admin
Posts: 184
Joined: Tue Sep 29, 2009 6:25 pm
Location: Moss Norway
Contact:

Unicoding in Python

Post by KBleivik »

1. Background links

Unicode HOWTO: http://docs.python.org/howto/unicode.html

Convert Unicode to ASCII without errors: http://stackoverflow.com/questions/2365 ... out-errors

2. Example
Consider the following executed in python’s 2.7 interactive interpreter:

Code: Select all

 >>> s = u'Ω'
    >>> se = s.encode("mbcs")
    >>> print s, se
    Ω Ω
    >>> s == se
    True
    >>> print s.lower(), se.lower()
    ω Ω
    >>> s.lower() == se.lower()
    False
Bizarre? Not if you consider that an ansi string has no way of knowing its encoding. Of course it could try to use the default encoding, but clearly it doesn’t. Python’s str.lower() does not convert non-ascii characters. See also a related question at Stackoverflow.
Source: http://pyscripter.blogspot.com/2012/02/ ... otcha.html

How can I do Unicode uppercase? http://stackoverflow.com/questions/7275 ... -uppercase

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest