Can't set attributes on instance of “object” class

后端 未结 7 1353
囚心锁ツ
囚心锁ツ 2020-11-22 10:10

So, I was playing around with Python while answering this question, and I discovered that this is not valid:

o = object()
o.attr = \'hello\'
<
7条回答
  •  广开言路
    2020-11-22 10:32

    https://docs.python.org/3/library/functions.html#object :

    Note: object does not have a __dict__, so you can’t assign arbitrary attributes to an instance of the object class.

提交回复
热议问题