thecocce / pyscripter

Automatically exported from code.google.com/p/pyscripter
0 stars 0 forks source link

Hook python messages #392

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Is there a way to hook python messages to translate them ? I think to classic 
messages like : 
"NameError: name 'n' is not defined"
or
"UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 
7: ordinal not in range(128)" when you try to execute a program whitch contain 
an accent in the name (french is painful with the accents !)

Vincent

Original issue reported on code.google.com by htcvi...@gmail.com on 18 Aug 2010 at 8:15

GoogleCodeExporter commented 9 years ago
If you find a way to do it in the standard Python interpreter the same way 
could be used in PyScripter, but I am not sure how this could be done.  This is 
not a PyScripter issue but a Python one.

Original comment by pyscripter on 18 Aug 2010 at 10:50

GoogleCodeExporter commented 9 years ago
This is off topic but regarding the support for file names that contain french 
characters the following info might be useful.

If you look the PyScripter help file in the topic "Encoded Python Source Files" 
(last paragraph) it tells you how to configure Python to support other 
encodings by modifying the site.py file.  This file is in the lib subdirectory 
of the Python installation directory.  Find the function setencoding and make 
sure that the support locale aware default string encodings is  on. (see below)

def setencoding():
    """Set the string encoding used by the Unicode implementation.  The
    default is 'ascii', but if you're willing to experiment, you can
    change this."""
    encoding = "ascii" # Default value set by _PyUnicode_Init()
    if 1:  <<<<<<<<<<<<<-------------------------------------
        # Enable to support locale aware default string encodings.
        import locale
        loc = locale.getdefaultlocale ()
        if loc[1]:
            encoding = loc[1]
    if 0:
        # Enable to switch off string to Unicode coercion and implicit
        # Unicode to string conversion.
        encoding = "undefined"
    if encoding != "ascii":
        # On Non-Unicode builds this will raise an AttributeError...
        sys.setdefaultencoding (encoding) # Needs Python Unicode build !

I think this should solve your problems

Original comment by pyscripter on 18 Aug 2010 at 10:51