write Unicode to sys.out.write without access to sitecustomize.py

Discussion in 'Python' started by Rob Knop, Aug 28, 2009.

  1. Rob Knop

    Rob Knop Guest

    I would like to tell the system that it's OK to write Unicode to sys.out
    and sys.err. However, I'm doing this in a CGI script where I don't have
    access to the system directories, and as such can't use
    sys.setdefaultencoding in sitecustomize.py.

    Is there a way to make this happen?

    --
    --Rob Knop
    E-mail:
    Home Page: http://www.pobox.com/~rknop/
    Blog: http://www.sonic.net/~rknop/blog/
    Rob Knop, Aug 28, 2009
    #1
    1. Advertising

  2. Rob Knop

    Guest

    On 02:51 pm, wrote:
    >
    >I would like to tell the system that it's OK to write Unicode to
    >sys.out
    >and sys.err. However, I'm doing this in a CGI script where I don't
    >have
    >access to the system directories, and as such can't use
    >sys.setdefaultencoding in sitecustomize.py.
    >
    >Is there a way to make this happen?


    Sure, just replace the two files with versions that know how to encode
    the unicode using the correct encoding:

    import sys, codecs
    info = codecs.lookup('utf-8') # for example
    sys.stdout = info.streamwriter(sys.stdout)
    sys.stderr = info.streamwriter(sys.stderr)

    Jean-Paul
    , Aug 28, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jamie
    Replies:
    1
    Views:
    2,103
    Thomas F.B.
    Nov 3, 2003
  2. F. GEIGER

    Umlauts, encodings, sitecustomize.py

    F. GEIGER, Nov 5, 2004, in forum: Python
    Replies:
    5
    Views:
    2,647
    Jeff Epler
    Nov 9, 2004
  3. Replies:
    3
    Views:
    526
    Terry Reedy
    Mar 22, 2014
  4. Chris Withers

    inconsistent sitecustomize.py importing...

    Chris Withers, Aug 25, 2009, in forum: Python
    Replies:
    1
    Views:
    299
    Steven D'Aprano
    Aug 25, 2009
  5. Chris Withers
    Replies:
    0
    Views:
    251
    Chris Withers
    Aug 25, 2009
Loading...

Share This Page