FAQ
Hi all~
My script can't work.I've changed my defaultencoding from 'ascii' to
'utf-8',but Python also raises a 'UnicodeEncodeError' error.

the error likes this:
s=u'La Pe\xf1a'
print s
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in position
5: ...

And in my script, there're many 'print' statements.So SOS~~~~
what should i do???
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110218/fa195396/attachment.html>

Search Discussions

  • Low kian seong at Feb 18, 2011 at 6:32 am

    On Fri, Feb 18, 2011 at 11:40 AM, tom z wrote:

    Hi all~
    My script can't work.I've changed my defaultencoding from 'ascii' to
    'utf-8',but Python also raises a 'UnicodeEncodeError' error.

    the error likes this:
    s=u'La Pe\xf1a'
    print s
    UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in
    position 5: ...
    s=u'La Pe\xf1a'
    print s.encode('utf-8')
    La Pe?a

    ? or use smart_str from django ?

    By the way did you lift that example from Dive Into Python ?


    And in my script, there're many 'print' statements.So SOS~~~~
    what should i do???

    --
    http://mail.python.org/mailman/listinfo/python-list

    --

    Low Kian Seong
    Senior Software Manager

    Logistics Consulting Asia
    M: +6 012 3736874 ? T: +60 3 7729 9386 ? F: +60 3 7729 7386
    www.logisticsconsulting.asia

    China ? India ? Indonesia ? Malaysia ? Philippines ? Singapore ?
    Thailand ? Vietnam
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20110218/d8b73932/attachment.html>

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedFeb 18, '11 at 3:40a
activeFeb 18, '11 at 6:32a
posts2
users2
websitepython.org

2 users in discussion

Low kian seong: 1 post Tom z: 1 post

People

Translate

site design / logo © 2022 Grokbase