Why can't I directly add attributes to any python object?

前端 未结 3 1711
情歌与酒
情歌与酒 2020-12-09 16:56

I have this code:

>>> class G:
...   def __init__(self):
...     self.x = 20
...
>>> gg = G()
>>> gg.x
20
>>> gg.y = 2000         


        
3条回答
  •  离开以前
    2020-12-09 17:18

    It's written in C

    http://svn.python.org/view/python/trunk/Modules/datetimemodule.c?view=markup

    It doesn't seem to implement setattr.

提交回复
热议问题