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, 开发者_C百科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!
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. :)
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
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.
精彩评论