Note that there are some explanatory texts on larger screens.

plurals
  1. POhelp() with unicode __author__ string
    primarykey
    data
    text
    <p>In the beginning of my scripts in Python 2.6, I would like to write my name as it is spelled, i.e. "Joël" (with trema on e). So I write <code>__author__ = u'Joël'</code>, and I can retrieve it by a simple <code>print __author__</code>.</p> <p>Problem appears with the built-in <code>help()</code> function, as I get an error message:</p> <pre><code>UnicodeEncodeError: 'ascii' codec can't encode character u'\xeb' in position 2: ordinal not in range(128) </code></pre> <p>I cannot upgrade to Python 3.x, and I find this function very helpful (and it will surely be for those who will get my scripts). I also did not forget to encode the files in UTF-8, and to specify it in the scripts by adding this:</p> <pre><code># -*- coding: utf-8 -*- </code></pre> <p>Any idea on where this comes from?</p> <p>Thanks in advance for your answers.</p> <hr> <p>EDIT Looking to the "Dive Into Python" book again, I found out how to have a correct render on my machine, see <a href="http://www.diveintopython.org/xml_processing/unicode.html" rel="nofollow">http://www.diveintopython.org/xml_processing/unicode.html</a>.</p> <p>The idea is that, my default encoding for Python was ASCII, and this did prevent help() to make a correct output. What I did is to add a script named like <code>sitecustomize.py</code> in <code>{pythondir}\Lib\site-packages</code>, setting the default encoding:</p> <pre><code>import sys sys.setdefaultencoding('iso-8859-1') </code></pre> <p>And now, with an input string written like <code>u'Joël'</code>, I get a correct output through call of help().</p> <p>Problem is, I'm quite sure that this will break on other's computers. Any idea how I could handle this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload