[Tutor] Declaring a global variable (where?)

Vicki Stanfield vicki@thepenguin.org
Mon Jun 30 12:42:42 2003


Hi all. First, I apologize for the blank email I sent earlier. I was using a new webmail client and in attempting to abandon the message, accidently did something that it interpreted as a send. Now onto business:

I am trying to declare a file handler as a global so that I can access from within any of my def blocks. I tried to add "global outfile" after the include statements at the beginning of the program and then use the same name in the assignement statement:

Class myClass:
    def __init__(self, parent, ID = -1, size = wxDefaultSize, style= -1):
[snip]
	self.outputfilesel = wxFileDialog(self, message="Choose output file.",
        defaultDir = "C:/",wildcard = "*.log", )
        self.outputfilesel.ShowModal()
        self.outputfilesel.Destroy()
        logfile = self.outputfilesel.GetFilename()
        outfile = open('C:/' +logfile, 'w')
[snip]

But I get a NameError: global name 'outfile' is not defined. Is this the appropriate place to place a global declaration?

--vicki