Search code examples
djangoutf-8titlecapitalize

How to capitalize the first letter of cyrillic word


Next problem:

>>> a = "привет"
>>> a.title()
'\xd0\xbf\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82'

>>> print(a.title())
привет

>>> from string import capwords
>>> capwords(a)
'\xd0\xbf\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82'

>>> print(capwords(a))
привет

>>> print(a.capitalize())
привет

With latin no problem, all works. I am working in Windows 7 now. I think in Linux this is not a problem.


Solution

  • Try this:

    >>> print u"привет".capitalize() #call the method on the unicode object
    Привет
    
    >>> a = "привет"
    >>> print a.decode('utf-8').capitalize() #decode str to unicode 
    Привет