473,387 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Could somebody please explain what is happening ....

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?

--
Best Regards
John
Jul 18 '05 #1
4 1619
>>>>> "John" == John Dean <jo**@rygannon.com> writes:
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

--
Ganesan R

Jul 18 '05 #2
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.
Jul 18 '05 #3
"John Dean" <jo**@rygannon.com> wrote in
news:3f***********************@lovejoy.zen.co.uk:
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.

--
Duncan Booth du****@rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
Jul 18 '05 #4
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?

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
---
Best Regards
John
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Kerim Borchaev | last post by:
Hello! Always when I use "super" I create a code duplication because class used as first arg to "super" is always the class where the method containing "super" was defined in: ''' class C:...
2
by: Abhish | last post by:
HI All ,:) I am a VC++ programmer,and some time My <b>Acumen</b> ask Microsofts VC++ (Visual Studio VC++ 6.0 )complier to complile my <b>senseless programs </b> ! :) <i><b> See what I have...
2
by: Chuck Rewood | last post by:
Hi, I am new in .NET and I'd like to build and application which control user's device. I've made a C# Windows application project that controls and run one of our POS device. Since I believe...
3
by: wesley.hall | last post by:
Hello, I have worked with XML fairly extensively but have generally used DTDs to describe the structure of my documents. Recently I decided to try to pick up XML Schemas and have been following...
5
by: jignasuk | last post by:
Hello, 1 unsigned char ar = "AB"; 2 unsigned int i = 0; 3 i = *(unsigned int *)ar; How does it convert to unsigned int from unsigned char()? After executing this three line I am getting...
10
by: Rav | last post by:
I have recently started working on GCC on red Hat 9. I have encountered with some problems that i think should not occur (at least on Turbo C), here they r: Why does the following piece of code...
7
by: gretean | last post by:
I have a problem that's driving me crazy involving Microsoft's ability to deduce template parameters. I am using Visual Studio .NET (aka VC7?), and it gives an error compiling the following code....
7
by: RobG | last post by:
Can someone explain to me why Firefox barfs on background and border in the following CSS and doesn't display the site the same as IE: #nav, #nav ul { background: <iw_value...
6
by: =?Utf-8?B?U2NvdHQgVHJpY2s=?= | last post by:
I followed the instructions from MSDN for Webclient UploadFile and I get an error: Could not find file 'C:\testfile.xls'. If I add the file (c:\testfile.xls) to the server I do not get the error...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.