Question

Can't figure this out. In Terminal, I import a module which instantiates a class, which I haven't figured out how to access. Of course, I can always instantiate in Terminal:

Server=Data.ServerData()

Then I can get a result:

Server.Property().DefaultChart

However, I want to skip that step getting the result directly from the instance already running in the module. I think Data.Server in this case should load the Server instance from when I imported Data:

Data.Server.Property().DefaultChart

>>> AttributeError: 'module' object has no attribute 'Server'

So how to access the running instance from Terminal?

Was it helpful?

Solution

If importing Data.py implicitly creates an instance of the Data.ServerData class (somewhat dubious, but OK in certain cases), that still tells us nothing about how that module chose to name that one instance. Do dir(Data) at the >>> prompt to see all the names defined in the Data module; if you want to see what names (if any!) have values that are instances of Data.ServerData, e.g.:

>>> [n for n in dir(Data) if isinstance(getattr(Data,n), Data.ServerData)]

Reading Data.py's source code might be simpler, but you do have many other options for such introspection to find out exactly what's going on (and how it differ from what you EXPECTED [[not sure on what basis!]] to be going on).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top