Could somebody please explain what is happening ....

Andrew Bennetts andrew-pythonlist at puzzling.org
Mon Sep 15 05:57:20 EDT 2003


On Mon, Sep 15, 2003 at 08:59:42AM +0000, John Dean wrote:
> Hi
> 
> I have been reading quite a lot of Python source code recently and I have
> come across a particular construct which I don't understand. I would be
> grateful if somebody could explain the reason for including the following
> lines of code. I have seen it only at the beginning of a module:-
> 
> global sys
> import sys
> 
> global os
> import os
> 
> ....
> ....
> 
> I know what global means and I know what import means but what is the reason
> for making an imported module global?

The 'global' statement is useless in the global scope (it only does
something useful inside functions), so I'm guessing that whoever wrote that
code didn't understand Python's 'global' statements.

-Andrew.






More information about the Python-list mailing list