2 Feb 2003 01:43
Re: Global scope
Pete Versteegen <pversteegen <at> gcnetmail.net>
2003-02-02 00:43:15 GMT
2003-02-02 00:43:15 GMT
Hi, I suppose one solution is to write a program that combines all of the individual modules into a single module so that it can access the global variable/list space. Pete Versteegen pversteegen <at> gcnetmail.net __________________________ On 2/1/03 4:31 PM, "Bob Gailer" <ramrom <at> earthling.net> wrote: > The scope of globals is the containing module. Thus "global case_number" > wants case_number to be in module myFunc1. It will NOT look anywhere else. > > Importing is hierarchical; main can import other modules, and can reference > objects therein; the imported modules can't see objects in the main module. > > Please tell us a bit more about what you want to accomplish, then we can > suggest alternatives. > > At 01:42 PM 2/1/2003 -0500, Pete Versteegen wrote: > >> It's not working.... Here is what I'm doing: >> >> The following code is saved in a file named main.py >> >> #!/usr/bin/python >> >> from myFunc1 import myFunc1 >> >> global case_number >> case_number = 0 >> >> last_case = myFunc1() >> >> print case_number >> >> >> >> The following code is saved in a file named myFunc1.py >> >> def myFunc1(): >> global case_number >> case_number += 1 >> >> >> When I execute main: ./main.py, I get: >> >> Traceback (most recent call last): >> File "./main.py", line 8, in ? >> last_case = myFunc1() >> File "./myFunc1.py", line 3, in myFunc1 >> case_number += 1 >> NameError: global name 'case_number' is not defined >> >> >> >> >> Pete Versteegen >> pversteegen <at> gcnetmail.net >> __________________________ >> >> >> >> _______________________________________________ >> Tutor maillist - Tutor <at> python.org >> http://mail.python.org/mailman/listinfo/tutor >> >> >> --- >> Incoming mail is certified Virus Free. >> Checked by AVG anti-virus system (http://www.grisoft.com). >> Version: 6.0.445 / Virus Database: 250 - Release Date: 1/21/2003 > > Bob Gailer > mailto:ramrom <at> earthling.net > 303 442 2625 > > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.445 / Virus Database: 250 - Release Date: 1/21/2003 > _______________________________________________ Tutor maillist - Tutor <at> python.org http://mail.python.org/mailman/listinfo/tutor
RSS Feed