Message80496
Run the following code
class A:
def __str__(self):
return "__str__"
def __unicode__(self):
return "__unicode__"
a = A()
print str(a), unicode(a)
print str(A), unicode(A)
----
Results on Python 2.5.4 (r254:67916):
__str__ __unicode__
__main__.A
Traceback (most recent call last):
File "/home/livibetter/tmp/unicode_classobj.py", line 14, in <module>
print str(A), unicode(A)
TypeError: unbound method __unicode__() must be called with A instance
as first argument (got nothing instead)
Results on Python 2.6.1 (r261:67515):
__str__ __unicode__
__main__.A __main__.A
----
I was expecting the same result as on 2.6.1. By my observation,
unicode(C) tries to invoke C.__unicode__ if __unicode__ is defined in C,
where C is a class object.
I believe this behavior is incorrect. |
|
Date |
User |
Action |
Args |
2009-01-25 05:40:42 | livibetter | set | recipients:
+ livibetter |
2009-01-25 05:40:40 | livibetter | set | messageid: <1232862040.08.0.372338675263.issue5050@psf.upfronthosting.co.za> |
2009-01-25 05:40:38 | livibetter | link | issue5050 messages |
2009-01-25 05:40:36 | livibetter | create | |
|