Pydev不会解析动态创建的属性

|| 问候, 我有一个奇怪的问题,我似乎无法解决: 我正在Windows XP上使用带有Eclipse Helios的pydev插件(如果有的话)。 我有一个包含一个类的模块。此类的“ 0”带有一个参数,该参数确定此类方法应具有的属性集。 由于不允许显示实际代码,因此可以给出以下类比:
class Car:
    def __init__(self, attrs):
        # attrs is a dictionary.
        # the keys of attrs are the names of attributes that this car should have
        # for example, a key of attr could be \'tires\'

        # the values of attrs are the values of the attributes which are the keys
        # so if the key is \'tires\', it\'s value might be 4
现在,由于我是在运行时动态设置这些变量的,所以当我这样做时,Pydev无法给我建议:
c = Car()
print c.tires
当我输入\“ c。\” +时,pydev不建议使用轮胎。 我如何才能获得此功能?还是pydev目前不能做的事情? 我将不胜感激     
已邀请:
这是所有动态语言IDE都会遇到的一个普遍问题。如果不执行代码,Pydev无法知道
Car.__init__
在Car实例上设置了哪些属性。如果将类变量用于在ѭ0中设置的属性,则Pydev应该能够提供自动完成建议。
class Car(object):
    tires = 4

    def __init__(self, attrs):
         self.tires = attrs.get(\'tires\', self.tires)
         self.tires += attrs.get(\'spare\', 0)
    
+1向Imran提出解决方案。但是,我想到了一个更好的解决方案:
Create all attributes in `__init__`.
When it comes time to be dynamic, delete the unwanted attributes.
这样,尽管在自动完成中仍建议使用所有属性的超集,但不会浪费内存。     

要回复问题请先登录注册