使用 Eclipse 自动补全 + PyDev 用于函数参数
我在 Windows XP 计算机上使用 Eclipse 和 PyDev 以及 Iron Python。我有一个类定义,它接受一个对象作为参数,它本身就是另一个类的实例化,如下所示:
myObject1 = MyClass1()
myObject2 = MyClass2(myObject1)
这两个类定义位于不同的模块 myclass1.py 和 myclass2.py 中,我希望我能够自动完成工作当在 myclass2 中使用 myObject1 时。换句话说,在文件 myclass2.py 中我可能有这样的内容:
""" myclass2.py """
class MyClass2():
def __init__(self, myObject1):
self.myObject1 = myObject1
self.myObject1. <============== would like auto code completion here
是否有可能使其工作?
谢谢!
I am using Eclipse and PyDev with Iron Python on a Windows XP machine. I have a class definition that takes an object as an argument which is itself an instantiation of another class like this:
myObject1 = MyClass1()
myObject2 = MyClass2(myObject1)
The two class definitions are in different modules, myclass1.py and myclass2.py and I was hoping I could get auto completion to work on myObject1 when it is being used in myclass2. In other words, in the file myclass2.py I might have something like this:
""" myclass2.py """
class MyClass2():
def __init__(self, myObject1):
self.myObject1 = myObject1
self.myObject1. <============== would like auto code completion here
Is it possible to make this work?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 PyDev/Eclipse 中使用 Jython,我也想知道这个问题。代码完成应该适用于您在 MyClass2 中其他地方使用过的 MyClass1 方法,但不适用于整个 API。我认为这是因为您可以动态添加和删除类中的方法,因此 Eclipse 无法保证任何特定方法存在,或者方法列表是完整的。
例如:
因此,如果代码完成在这里向您显示方法 b(),那么它将是不正确的。
同样,
未显示方法 b() 的代码完成将是不正确的。
我可能是错的,但我认为这是一个可靠的猜测。 :)
Using Jython in PyDev/Eclipse, I've wondered about this too. Code completion should work for MyClass1 methods you've used somewhere else in MyClass2, but not for the entire API. I think it's because you can add and remove methods from a class on the fly, so Eclipse can't guarantee that any particular method exists, or that a list of methods is complete.
For example:
So if code completion showed you the method b() here, it would be incorrect.
Similarly,
So code completion that didn't show the method b() would be incorrect.
I could be wrong, but I think it's a solid guess. :)
使用垃圾邮件行(
if False ...
)创建对象,我的 Pydev 2.5 没问题。With a spam line (
if False ...
) with creating object, it's OK with my Pydev 2.5.您的源文件夹中有
__init__.py
吗?它可以为空,但它应该存在于所有文件夹中,以便 Python 知道读取其中包含的类文件以实现自动完成的目的。Do you have an
__init__.py
in your source folder? It can be empty, but it should exist in all folders so that Python knows to read the files contained therein for Classes for the purpose of autocompletion.