What is the consensus on the best way reference module level variables? I have a wx app that has grown too large, so I started to do some housekeeping. I'm trying to move several functions outside of the main module while still being able to reference the main variables.. The program works if I include

from __main__ import *

at the top of the child modules, however it only works once. If I run the script without completely closing all python windows it raises

Traceback (most recent call last):
  File "C:\Python25\Lib\roster\roster_main.pyw", line 427, in Login
    Conform.Run()
  File "C:\Python25\Lib\roster\Conform.py", line 197, in Run
    window.UpdateSearch()
  File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 14528, in __getattr__
    raise PyDeadObjectError(self.attrStr % self._name)
wx._core.PyDeadObjectError: The C++ part of the MainFrame object has been deleted, attribute access no longer allowed.

Is there a better way to do this?

Recommended Answers

All 3 Replies

I suggest you write yourself a small test model program.

.. Okay. I'm just not quite sure of where to start, I'm sure you've had some experience with this. I've looked at several other package modules and have really only seen explicit import calls ( importing each variable by name )

from __main__ import * must not be written if you want to write maintainable code. What you should do is first see if some parts of your program can be implemented as separate modules, at functional level (for example a module could be devoted to communicate with a database, etc). The variables that you have in __main__ could become members of a single object which could be passed to functions and classes in other modules.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.