I have the following Unicode text stored in variable:
myvariable = 'Gen\xe8ve'
What I want to do is to print myvariable
and show this:
Genève
I tried this but failed:
print myvariable.decode('utf-8')
What's the right way to do it? At the end I'd like to print the string into a text file. I'm using Python 2.7.
Update: Also tried this:
In [23]: myvariable = u'Gen\xe8ve'
In [24]: print myvariable
---------------------------------------------------------------------------
UnicodeEncodeError Traceback (most recent call last)
<ipython-input-24-1eb59a50889d> in <module>()
----> 1 print myvariable
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 3: ordinal not in range(128)
Update 2:
I really want to print from myvariable
. In actual code Gen\xe8ve
are extracted from xml.etree.ElemTree parser, like:
myvariable = actress.find('name').text
## The following doesn't work.
# print u'myvariable'