question on global variables
Jeff Davis
jdavis at empires.org
Thu Oct 10 00:46:29 EDT 2002
'global' is for use in a function body to call a global variable to the
local scope. To declare a new global variable, simply declare it in the
global scope, i.e.:
-------begin myscript.py--------
foo = 'string' #global variable
def fn():
global foo # brings 'foo' into the local scope
print foo #prints global variable 'foo'
fn()
-------end myscript.py--------
Regards,
Jeff
mongo57a at comcast.net wrote:
> Somewhat new to Python here.....
>
> I want to change/use a value throughout my program - what I would
> normally refer to as a "global" variable.
>
> I see that there is a "global" command - and I assume its use would be
> global var_name. This I have coded (works) but I am unable to use it
> "global name var_name is not defined".
>
> TIA
>
>
> -----------== Posted via Newsfeed.Com - Uncensored Usenet News
> ==----------
> http://www.newsfeed.com The #1 Newsgroup Service in the World!
> -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers
> =-----
More information about the Python-list
mailing list