使用 Eclipse 自动补全 + PyDev 用于函数参数

发布于 2024-09-07 13:31:16 字数 548 浏览 3 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柏林苍穹下 2024-09-14 13:31:16

在 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() 的代码完成将是不正确的。

我可能是错的,但我认为这是一个可靠的猜测。 :)

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:

>>> 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'

So if code completion showed you the method b() here, it would be incorrect.

Similarly,

>>> 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

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. :)

笑着哭最痛 2024-09-14 13:31:16

使用垃圾邮件行(if False ...)创建对象,我的 Pydev 2.5 没问题。

""" myclass2.py """
    class MyClass2():
    def __init__(self, myObject1):
        if False : myObject1 = MyClass1()
        self.myObject1 = myObject1        
        self.myObject1.  <============== would like auto code completion here

With a spam line (if False ...) with creating object, it's OK with my Pydev 2.5.

""" myclass2.py """
    class MyClass2():
    def __init__(self, myObject1):
        if False : myObject1 = MyClass1()
        self.myObject1 = myObject1        
        self.myObject1.  <============== would like auto code completion here
小帐篷 2024-09-14 13:31:16

您的源文件夹中有 __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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文