我在 Windows XP 机器上将 Eclipse 和 PyDev 与 Iron Python 结合使用。我有一个类定义,它以一个对象作为参数,它本身是另一个类的实例化,如下所示:
myObject1 = MyClass1()
myObject2 = MyClass2(myObject1)
这两个类定义在不同的模块中,myclass1.py 和 myclass2.py,我希望当 myObject1 在 myclass2 中使用时,我可以自动完成它。换句话说,在文件 myclass2.py 中我可能有这样的东西:
""" myclass2.py """
class MyClass2():
def __init__(self, myObject1):
self.myObject1 = myObject1
self.myObject1. <============== would like auto code completion here
是否有可能使这项工作成功?
谢谢!
最佳答案
在 PyDev/Eclipse 中使用 Jython,我也想知道这个问题。代码完成应该适用于您在 MyClass2 的其他地方使用过的 MyClass1 方法,但不适用于整个 API。我认为这是因为您可以动态地在类中添加和删除方法,所以 Eclipse 不能保证任何特定的方法存在,或者方法列表是完整的。
例如:
>>> class a:
... def b(self):
... print('b')
...
>>> anA = a()
>>> anA.b()
b
>>> del a.b
>>> anA.b()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: a instance has no attribute 'b'
因此,如果代码完成向您显示了此处的方法 b(),那将是不正确的。
同样,
>>> class a:
... pass
...
>>> anA = a()
>>> anA.b()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: a instance has no attribute 'b'
>>> def b(self):
... print('b')
...
>>> a.b = b
>>> anA.b()
b
所以没有显示方法 b() 的代码完成是不正确的。
我可能是错的,但我认为这是一个可靠的猜测。 :)
关于python - 使用 Eclipse + PyDev 自动完成函数参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3153761/