FAQ
It gets tedious to have to append .encode('utf-8') to all my unicode
strings when I print them, as in:

print foobar.encode('utf-8')

I want to tell python to apply this encoding automatically to
anything argument passed to print.

How can I do this?

TIA!

K

PS: BTW, sys.setdefaultencoding is *not* the answer, since this
method gets removed by site.py...

Search Discussions

  • Diez B. Roggisch at Jan 31, 2010 at 3:54 pm

    Am 31.01.10 16:38, schrieb kj:
    It gets tedious to have to append .encode('utf-8') to all my unicode
    strings when I print them, as in:

    print foobar.encode('utf-8')

    I want to tell python to apply this encoding automatically to
    anything argument passed to print.

    How can I do this?

    TIA!

    K

    PS: BTW, sys.setdefaultencoding is *not* the answer, since this
    method gets removed by site.py...
    Just wrap sys.stdout in a codecs-module based file-wrapper.

    import codecs
    import sys

    sys.stdout = codecs.getwriter("utf-8")(sys.stdout)

    print u"?"



    Diez
  • Kj at Jan 31, 2010 at 4:28 pm
    In <7slndhFnomU1 at mid.uni-berlin.de> "Diez B. Roggisch" <deets at nospam.web.de> writes:
    Am 31.01.10 16:38, schrieb kj:
    It gets tedious to have to append .encode('utf-8') to all my unicode
    strings when I print them, as in:

    print foobar.encode('utf-8')

    I want to tell python to apply this encoding automatically to
    anything argument passed to print.

    How can I do this?

    TIA!

    K

    PS: BTW, sys.setdefaultencoding is *not* the answer, since this
    method gets removed by site.py...
    Just wrap sys.stdout in a codecs-module based file-wrapper.
    import codecs
    import sys
    sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
    print u"??"
    That's exactly what I was looking for. Thanks!

    kynn

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJan 31, '10 at 3:38p
activeJan 31, '10 at 4:28p
posts3
users2
websitepython.org

2 users in discussion

Kj: 2 posts Diez B. Roggisch: 1 post

People

Translate

site design / logo © 2022 Grokbase