Search code examples
pythoneclipsedynamicpydevresolve

Pydev won't Resolve Dynamically created Attributes


Greetings SO,

I have a weird problem that I don't seem to be able to solve:

I am working with the pydev plugin with eclipse Helios on Windows XP (if it matters).

I have a module which contains a class. The __init__ of this class takes a parameter which determines the set of attributes that a method of this class should have.

Since I am not allowed to show actual code, I can give the following analogy:

class Car:
    def __init__(self, attrs):
        # attrs is a dictionary.
        # the keys of attrs are the names of attributes that this car should have
        # for example, a key of attr could be 'tires'

        # the values of attrs are the values of the attributes which are the keys
        # so if the key is 'tires', it's value might be 4

Now, since I'm setting these variables dynamically at runtime, Pydev is not able to give me suggestions when I do this:

c = Car()
print c.tires

When I type in "c." +, pydev does not offer tires as a suggestion.

How might I go about getting this functionality? Or is it just not something that pydev can do at present?

I'd appreciate any help


Solution

  • +1 to Imran for his solution. But, Ia better solution occurred to me:

    Create all attributes in `__init__`.
    When it comes time to be dynamic, delete the unwanted attributes.
    

    This way, ene though the superset of all attributes is still suggested in the autocomplete, memory is not wasted.