What does the keyword 'global' really mean

John Roth newsgroups at jhrothjr.com
Tue Sep 9 07:41:46 EDT 2003


"John Dean" <john at rygannon.com> wrote in message
news:3f5db3b6$0$252$fa0fcedb at lovejoy.zen.co.uk...
> Hi
> I have been looking through some Python code and I came across the keyword
> 'global'. I have looked through the docs and two or three Python
programming
> books for a full explanation of what 'global' really means. Would I be
> correct in assuming that any variable prefixed with the keyword global
would
> allow that variable to be accessible across translation units, in other
> words global is equivalent to the 'C' keyword 'extern' ?

No. What global does is tell the compiler that assignments to that
identifier are at the module level, they are not local to the function or
method.

There is no equivalent to 'extern.' If you want to reference something
in another module, you import the module, then all the identifiers are
availible.

> Also, does Python have the equivalent of the 'C' keyword 'static'?

IIRC, static means that it's global to the compilation unit. Python does
not need such a keyword, just bind something at the module or class
level.

John Roth
>
> -- 
> Best Regards
> John






More information about the Python-list mailing list