为什么代码分析“可以”?初始化类变量但不读取该变量?
我对 python 很陌生,正在进行测试:
class MyTest(MyParentTest):
@classmethod
def setUpClass(cls):
super(MyTest, cls).setUpClass()
cls.ipg_model = ngty.data_model.DataModel(
...
)
ipg_object = cls.ipg_model.create(ngty)
从上面开始,IDE 允许我执行 cls.ipg_model = ,但是当我尝试 cls.ipg_model.create( 时它说“类'RestClassTest'的未解析的属性引用'ipg_model'”
IDE建议在方法之外声明变量(这就是python教授类变量的方式) - 这可能会起作用,但我觉得我可以学到一些关于 python 工作原理的有趣知识:)
I am quite new to python and working on a test:
class MyTest(MyParentTest):
@classmethod
def setUpClass(cls):
super(MyTest, cls).setUpClass()
cls.ipg_model = ngty.data_model.DataModel(
...
)
ipg_object = cls.ipg_model.create(ngty)
From above, the IDE allows me to do cls.ipg_model =
but when I try cls.ipg_model.create(
then it says "unresolved attribute reference 'ipg_model' for class 'RestClassTest'"
The IDE suggests to declare the variable outside of the methods (and that's how python teaches class variables) - and that'll probably work but I feel like I could learn something interesting about how python works :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论