[Python-3000] Draft PEP for outer scopes
Nick Coghlan
ncoghlan at gmail.com
Mon Nov 6 10:37:36 CET 2006
Andrew McNamara wrote:
>> Python, C/C++, JavaScript, Ruby, and Perl all have this in common:
>>
>> A "global variable" is visible to the entire file and does
>> not belong to any particular function.
>
> I note that you didn't say "a global variable is visible to the entire
> application" - you've deliberately narrowed the definition to suit
> your argument.
In C/C++ to use another module's 'globals' you must redeclare their names in
the current module (usually with a #include of the appropriate header file).
The linker then takes care of associating the two declarations with the same
defining module.
In C, each symbol must be unique. In C++, the global variables may be in
different namespaces, requiring either scope qualification or an appropriate
using statement to access the names in the namespace.
In Python, to use another module's globals you must import the module. You can
then accessing the name as an attribute of the imported module (or you can use
the alternate form of import and retrieve only the globals you are interested in).
So tell me again how Python's globals are different from C++ ones? Sure, the
linkage is done at runtime rather than build time, but the module cache means
they're still global to the application (accessible from everywhere, always
refer to the same object).
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-3000
mailing list