Re: getdefaultencoding - how to change this?



On Thu, 20 Jan 2011 10:46:37 -0600, Robert Kern wrote:

On 1/20/11 8:31 AM, Helmut Jarausch wrote:
Hi,
I've searched the net but didn't find the information I need. Using
Python-2.7.1, I know, I can't modify defaultencoding at run time.

You're not supposed to. It must remain 'ascii'. Otherwise, you will
break dict lookups among other things. Can you be specific about why you
think you want to change this? What are you trying to achieve? It looks
like you are conflating a variety of different behaviors below.

Python even ignores
export PYTHONIOENCODING=ISO8859-1

locale.getdefaultlocale()[1]
returns
'ISO8859-1'

This does not introspect the same thing as sys.getdefaultencoding().

still sys.stdout is using the ascii codec.

This reflects your terminal settings, not sys.getdefaultencoding(). I'm
not sure why the PYTHONIOENCODING variable isn't affecting that. It
works fine for me.

How can I recompile Python (itself) to change this to iso8859-1 ? (My
favourite editor cannot be told to use unicode.)

You wouldn't want to change sys.getdefaultencoding() for this. That
parameter affects how str and unicode objects are converted between each
other without an explicit .encode()/.decode() call, not what encoding
Python assumes for the parsing of the code.

Instead, you want to use an encoding declaration in each file:

http://docs.python.org/reference/lexical_analysis.html#encoding-
declarations

Thanks Robert,
probably I wasn't too clear about my issue.
I couldn't "print" any non-ascii character to my console although
my console has an en_US.iso88591 locale.

I didn't modfiy anything in Python's source code.
I noticed that my root account still had an ASCII locale.
Now I have changed it such that the root account has the same locale
as non-root accounts. Recompiling Python under such a root account
has rectified things. Now I can print non-ascii characters if they are
properly encoded.

Thanks,
Helmut.




--
.



Relevant Pages

  • Re: getdefaultencoding - how to change this?
    ... I couldn't "print" any non-ascii character to my console although ... I noticed that my root account still had an ASCII locale. ... Recompiling Python under such a root account ...
    (comp.lang.python)
  • Re: Unicode conversion in print
    ... informaion on when and why Python started doing it (previously, ... > locale to get the encoding of console: ...
    (comp.lang.python)
  • Re: security problem: console text gets sent to printer
    ... The text is printed out just like it's shown in the console, ... time text was printed from the root account, ... Is "common sense" really valid? ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)
  • Whats with the "Dont login as root, use su" message?
    ... I have what is probably a dumb question: ... I am curious from a security point of view why it says that root should ... logged into root account on the console. ...
    (comp.unix.bsd.openbsd.misc)
  • security problem: console text gets sent to printer
    ... On two different occasions over the past month, text from the console ... time text was printed from the root account, the second time it was ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx with a subject of "unsubscribe". ...
    (Debian-User)