Reputation: 581
Why are __dict__
and for example __unicode__
not both callable or the other way around?
Django tells me to set a unicode return as a method on an Model, for example:
class Obj(models.Model):
def __unicode__(self):
return 'hey'
>>> x = Obj()
<__main__.Obj object at 0x100703e10>
>>> x.__unicode__()
u'hello'
>>> x.__dict__
{}
It seems an odd discrepancy, can anyone explain it to me?
Upvotes: 4
Views: 837
Reputation: 363818
The __foo__
convention is used for both methods and non-callable attributes in Python. __unicode__
is a method, __dict__
is not.
Upvotes: 4
Reputation: 20580
__dict__
is the dictionary of the instance, not a method.
Upvotes: 0