Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting words with String upper() does not work for certain letters?

Hello guys I hope you can help me with this problem, I've have hours trying to solve it

Using this code:

#!/usr/bin/python
# -*- encoding: utf-8 -*-

frase = 'La canción de la piña'
print frase.upper()

I just get "LA CANCIóN DE LA PIñA", the problem is that it does not make the "ñ" in to a "Ñ" or "ó" in "Ó"

Any idea ?

like image 945
El arquitecto Avatar asked Jul 03 '16 01:07

El arquitecto


1 Answers

Use unicode literal (string literal with leading u) to represent unicode string:

>>> frase = u'La canción de la piña'
>>> print frase.upper()
LA CANCIÓN DE LA PIÑA

UPDATE

Adding following line at the beginning of the file enables automatic unicode literals. (In interactive shell, statements follow the import statements will be affected.)

from __future__ import unicode_literals

See __future__ - future statement definitions.

like image 102
falsetru Avatar answered Oct 22 '22 00:10

falsetru