I'm teaching myself Python using the command-line interpreter (v3.5 for Windows).
All I want to do is output some text that includes the euro (€) symbol which I understand to be code 80h (128 dec).
#!
# -*- coding: utf-8 -*-
mytext = 'Please pay \x8035.'
print(mytext)
It falls over on the last line:
UnicodeEncodeError: 'charmap' codec can't encode character '\x80' in position 11: character maps to <undefined>
I've done lots of googling (re encodings etc) and I've a rough idea why the print command fails. Tinkering with the above code shows that ASCII codes up to \x7f work fine, as one might expect.
But I can't figure out how to display the €, and I'm finding the information on encodings overwhelming and impenetrable. (Remember I'm just a noob!)
- I've tried prefixing the text string with u to create a unicode string in the first place.
- I've tried creating an intermediate object outputtext = mytext.encode('utf-8') but outputting this with print expands the string into an even more cryptic form: b'Please pay \xc2\x8035.'
- I've tried to find a different function instead of print to output this intermediate string, but nothing has worked yet.
Please can someone show me some code that just works, so I can study it and work backwards from there. Thanks!