|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
class MyProperty:
def __init__(self,fget=None,fset=None,fdel=None):
self.fget = fget
self.fset = fset
self.fdel = fdel
def __get__(self,instance , owner):
return self.fget(instance)
def __set__(self,instance,owner):
self.fset(instance,value)
def __delete__(self,instance):
self.fdel(instance)
class C:
def __init__(slef):
self._x = None
def getX(self):
return self._x
def setX(self,value):
self._x = value
def delX(self):
del self._x
x = MyProperty(getX,setX,delX)
当我执行的时候
c = C()
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
c = C()
File "E:/py/小甲鱼课后作业/property本质.py", line 18, in __init__
self._x = None
NameError: name 'self' is not defined
哪里错了吗,和小甲鱼的代码一样的
def __init__(slef): # 应该是self。换pycharm或vscode编辑器,这种拼写问题都会帮你检查的。
|
|