Could somebody please explain what is happening ....

J

John Dean

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?
 
G

Ganesan R

John" == John Dean said:
I know what global means and I know what import means but what is the reason
for making an imported module global?

I can't think of any reason for doing that. May be, sys or os are being
re-assigned somewhere in the code (which would be a weird thing to do).

Ganesan
 
A

Andrew Bennetts

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.
 
D

Duncan Booth

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?

None whatsoever. This isn't a construct used by anyone who knows what the
global statement does: outside a function global has precisely no effect.
 
J

John Dean

John said:
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?
Thank you to all who posted an answer. I was begining to think I was going
nuts or something. Even though I am new to Python I knew something was
wrong
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top