ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-Tutor
python-Tutor
[Tutor] Declaring a global variable (where?)
by Vicki Stanfield other posts by this author
Jun 30 2003 4:09PM messages near this date
Re: [Tutor] Function Programming Style | Re: [Tutor] Declaring a global variable (where?)
Hi all. First, I apologize for the blank email I sent earlier. I was using a new webmail cli
ent and in attempting to abandon the message, accidently did something that it interpreted a
s 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 o
f 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 t
o place a global declaration?

--vicki        

_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Vicki Stanfield
Abel Daniel

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved