Why is there no __dict__ called

Why are __dict__ and, for example, __unicode__ not both called, or vice versa?

Django tells me that to return as unicode as a method on a 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 like a strange mismatch, can someone explain this to me?

+4
source share
2 answers

The __foo__ used for both methods and non-invoked attributes in Python. __unicode__ is a method, __dict__ not.

+4
source

__dict__ is an instance dictionary, not a method.

0
source

Source: https://habr.com/ru/post/1480510/


All Articles