Python的描述符“\uu get\uuuuuuu”没有像我预期的那样被调用,原因是什么?

2024-04-25 12:00:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我在尝试python的get描述符,看看是否调用了它

我得到了以下信息:

"""This is the help document"""
class c1(object):
    """This is my __doc__"""
    def __get__(s,inst,owner):
      print "__get__"

    def __init__(s):
      print "__init__"
      s.name='abc'

class d(object):
    def __init__(s):
    s.c=c1()

d1=d()
d1.c
print d1.c.name

我希望它将调用get函数。但事实上输出是

__init__
abc

为什么“d1”的实例所有者没有调用我的“get”函数

谢谢


Tags: 函数name信息getobjectinitisdef