Rob McMullen wrote:
Can someone please explain to me why this does not work and suggest a way of
accomplishing my objective.It's because you use print_const in the constructor of your MainFrame,
and python hasn't completed building the class. Until the constructor
returns, the reference to the MainFrame isn't valid in your app.
Also note that you are putting CONSTANT in your frame class -- does it belong there, or should it be an attribute of the app itself. The way you have it violates the "law of Demeter" -- now anything working with the app needs to know that it has a "frame" attribute, and that the frame attribute as a "CONSTANT" attribute -- no too bad, but starting to get too deep.
Also, I know this is probably a simplified sample, but:
class MainFrame(wx.Frame):
CONSTANT = 3
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
print_const()
Why would you want to call a global function to print an attribute of your frame class, from that class?
In general, I avoid global functions altogether -- why not have print_const() be a method of your app?
-Chris
ยทยทยท
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov