unicode bit me

rurpy at yahoo.com rurpy at yahoo.com
Sat May 9 18:41:45 CEST 2009


On May 9, 10:08 am, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> On Sat, 09 May 2009 08:37:59 -0700, anuraguni... at yahoo.com wrote:
> > Sorry being unclear again, hmm I am becoming an expert in it.
>
> > I pasted that code as continuation of my old code at start i.e
> >  class A(object):
> >      def __unicode__(self):
> >          return u"©au"
>
> >      def __repr__(self):
> >          return unicode(self).encode("utf-8")
> >      __str__ = __repr__
>
> > doesn't work means throws unicode error my question
>
> What unicode error?
>
> Stop asking us to GUESS what the error is, and please copy and paste the
> ENTIRE TRACEBACK that you get. When you ask for free help, make it easy
> for the people trying to help you. If you expect them to copy and paste
> your code and run it just to answer the smallest questions, most of them
> won't bother.
>
> --
> Steven

Creua H Jiest!

It took me less then 45 seconds to open a terminal window, start
Python, and paste the OPs code to get:
>>> class A(object):
...      def __unicode__(self):
...          return u"©au"
...      def __repr__(self):
...          return unicode(self).encode("utf-8")
...      __str__ = __repr__
...
>>> print unicode(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined
>>> a=A()
>>> print unicode(a)
©au
>>> print unicode([a])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position
1: ordinal not in range(128)

Which is the same error he had already posted!

I am all for encouraging posters to provide a good description
but let's not be ridiculous.

Anecdote:
My sister always gives her dogs the table scraps after eating
dinner.  One day when I ate there, I tossed the dogs a piece
of meat I hadn't eaten.  "No", she cried!  "You mustn't give
him anything without making him do a trick first!  Otherwise
he'll forget that you are the boss!".



More information about the Python-list mailing list