Discuss / Python / (救救孩子吧)AttributeError: 'c' object attribute 'getname' is read-only

(救救孩子吧)AttributeError: 'c' object attribute 'getname' is read-only

Topic source
from types import MethodType
class c(object):
    __slots__=("name","age","getname")
    passc1=c()
c1.name="harry"def getname(self):
    print(self.name)
c.getname=getname
c1.getname=MethodType(getname,c1)
c1.getname()

  • 1

Reply