views:

271

answers:

4

Hello, I am using eclips for python and i am facing a problem. I have many classes with many properties and want a list of objects from one of my declared classes. The problem is:When i am accessing any item from the list, the IDE does not know it's type because in python we do not declare the variable with it's type, so there is no auto complete and i have to go to the class to copy the attribute name. To make idea more clear:

class AutomataBranch(object):
    def __init__(selfparams):
        self.Name="";
        self.nodes=[];

class LanguageAutomata(object):    
    def __init__(selfparams):
        self.cfgAutomata=[];#This has AutomaBranch Type

Now in any method in LanguageAutomata class if i wrote: cfgAutomata. Then it wont give me the Name attribute Is there any solution for that?

+4  A: 

You shouldn't be writing code to suit your IDE - the IDE is supposed to support you. If you're having trouble with it, then switch. There are plenty of editors that deal with Python properly.

Daniel Roseman
There is no IDE that will find the type of self.cfgAutomata[0] with the above code, as there is no way to know its type (outside of a subclass of Object).
Kathy Van Stone
Actually I am using pydev and as you said there is no way to let the IDE or even python interpreter to know whether the property Name exists or not.What i want is to way that let me write:"AutomataBranch x" such that when i add x. then it helps and view the Name property.
Hani
A: 

I think i found a good managable solution. Actually it is trivial but may help (I used it now). When i want to access the list then i assign the object which i want to access to a variable ex: 1)x=AutomataBranch() 2)x=self.cfgAutomata[i]

The first line is used only to make the IDE knows that x is from AutomatBranch type.After that when i press x. then all methods and properties are visualized.

I think it is some how good. Hani Almousli...

Hani
This is a very bad idea. Coding in a special way to make autocompletion works, this is CRAZY.
e-satis
Perhaps you are right but the problem lies beyond the fact that i am always using Microsoft Visual Studio and suddenly changing to a new IDE is not that easy.Of course i am going to refactor my code after getting it works.Thanks for your advice.Hani Almousli....
Hani
+2  A: 

Python is strongly typed and Python lists are too. Your problem come from the fact that Python is dynamically typed. Therefor a var can contain any type, and therefor no IDE can guess what is the type of your parameter, nor give you code completion for the methods.

This is how it is, there is no clean workaround. If it's a problem, then maybe dynamics language is not you predilection tool and you should use something that fit your development style. There are tools for everybody.

e-satis
+2  A: 

I think you mean to say "statically typed" instead of "strongly typed." Python is strongly typed. You just don't know what that type is at compile time.

With that said, you really need to abandon the idea that you're going to find any IDEs that work as well for Python as they do for Java or C#. Python's dynamic typing makes this difficult. In fact, I tend to find that powerful IDEs are more of a burden than a help.

Jason Baker