How can I print a euro (â¬) symbol in Python?
<p>I'm teaching myself Python using the command-line interpreter (v3.5 for Windows).</p>

<p><strong>All I want to do is output some text that includes the euro (â¬) symbol</strong> which I understand to be code 80h (128 dec).</p>

<pre><code>#!
# -*- coding: utf-8 -*-

mytext = 'Please pay \x8035.'
print(mytext)
</code></pre>

<p>It falls over on the last line:</p>

<pre><code>UnicodeEncodeError: 'charmap' codec can't encode character '\x80' in position 11: character maps to &lt;undefined&gt;
</code></pre>

<p>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.</p>

<p>But I can't figure out how to display the <strong>â¬</strong>, and I'm finding the information on encodings overwhelming and impenetrable. (Remember I'm just a noob!)</p>

<ul>
<li>I've tried prefixing the text string with <em>u</em> to create a unicode string in the first place.</li>
<li>I've tried creating an intermediate object <em>outputtext = mytext.encode('utf-8')</em> but outputting this with <em>print</em> expands the string into an even more cryptic form: <em>b'Please pay \xc2\x8035.'</em></li>
<li>I've tried to find a different function instead of <em>print</em> to output this intermediate string, but nothing has worked yet.</li>
</ul>

<p>Please can someone show me some code that <strong>just works</strong>, so I can study it and work backwards from there. Thanks!</p>

<p>Here are four ways of printing a string with the Euro symbol in Python 3.x, in increasing order of obscurity.</p>

<p><strong>1. Direct input</strong></p>

<p>Use your keyboard to enter the symbol, or copy and paste it from somewhere else:</p>

<pre class="lang-py prettyprint-override"><code>mytext = "Please pay â¬35."
print(mytext)
</code></pre>

<p><strong>2. Use Unicode glyph number</strong></p>

<p>Look up the Unicode glyph number, for example from the very useful page <a href="http://www.fileformat.info/info/unicode/" rel="nofollow">http://www.fileformat.info/info/unicode/</a>, and use that code in your string:</p>

<pre class="lang-py prettyprint-override"><code>mytext = "Please pay \u20ac35."
print(mytext)
</code></pre>

<p><strong>3. Use glyph name</strong></p>

<p>You can use <a href="https://docs.python.org/3.5/library/unicodedata.html" rel="nofollow"><code>lookup()</code></a> from the <code>unicodedata</code> module to access Unicode glyphs by name. Again <a href="http://www.fileformat.info/info/unicode/" rel="nofollow">http://www.fileformat.info/info/unicode/</a> will help you find the glyph name:</p>

<pre class="lang-py prettyprint-override"><code>import unicodedata

mytext = "Please pay {}35.".format(unicodedata.lookup("EURO SIGN"))
print(mytext)
</code></pre>

<p><strong>4. Use Windows-1252 codepage</strong></p>

<p>If you really want to use the <code>\x80</code> byte code, you can do that, because it represents the Euro symbol in the Windows-1252 codepage. What you need to do is first create a byte string containing that byte code, and then decoding that byte string so that the byte code is translated to the Euro symbol entry in the Windows-1252 codepage:</p>

<pre class="lang-py prettyprint-override"><code>mytext = b"Please pay \x8035.".decode("windows-1252")
print(mytext)
</code></pre>

python utf-8 character-encoding