相关疑难解决方法(0)

AttributeError:'property'对象没有属性

Python(2.6)似乎无缘无故,任何人都可以看到这个代码有问题吗?

class DB ():
    def doSomething (self, str):
        print str

class A ():
    __db = DB()

    @staticmethod
    def getDB ():
        return A.__db

    db = property(getDB)


A.db.doSomething("blah")
Run Code Online (Sandbox Code Playgroud)

失败,例外情况:

AttributeError:'property'对象没有属性'doSomething'

我的理解是,一个属性在访问时会自动运行它的getter,那么为什么它会抱怨一个属性对象,为什么它找不到我明显可用的方法呢?

python properties exception class object

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

class ×1

exception ×1

object ×1

properties ×1

python ×1