Alan/Jim:

It's good to hear some pragmatic advice.  

This particular module has 8 small functions that share common data 
(structures, primarily in arrays and vectors).  I tried passing array_G as a 
parameter but that doesn't work because everything in the function remains 
local and I cannot get back the altered data (unless you know better?). 

The 'global' route works a treat so far.

Dinesh

...............................................................
Date: Tue, 13 Nov 2007 23:11:49 -0000
From: "Alan Gauld" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] global is bad but ...
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
reply-type=original

"Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote

> Consider a data structure (say, an array) that is operated 
> on by a bunch of functions eg.
>
> def function_A
>     global array_G

> def function_B
>     global array_G

> etc...

> On the other hand, wiser heads say that the use of 'global' 
> is bad and that reworking the code into classes and objects 
> is better.

Rather than answer your question directly can I ask, do 
you know *why* wiser heads say global is bad? What 
problems does using global introduce? What problems 
does it solve?

> What do you think and suggest?

I think it's better to understand issues and make informed 
choices rather than following the rules of others.

I suggest you consider whether global is bad in this case 
and what other solutions might be used instead. Then make 
an informed choice. If, having researched the subject you 
don't understand why global is (sometimes) bad ask for 
more info here.

HTH (a little),

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld



_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to