D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] Global variables in Python?

 

On 27 April 2013 23:23, Martijn Grooten <sweetwatergeek@xxxxxxxxx> wrote:
On Sat, Apr 27, 2013 at 11:12 PM, Grant Phillips-Sewell wrote:
> Now, to my brain since SOMEVAR is a global variable, the contents should be
> accessible from any part of the code, and should be changeable from any part
> of the code too.
>
> Am I thinking about, or implementing this in completely the wrong way?

This seems to suggest that inside the function, you have to declare
SOMEVAR as a global variable:

http://stackoverflow.com/questions/10588317/python-function-global-variables

Not sure if also declaring it as global near the top of you're program
makes a difference, but then I don't use Python very much. (Nor do I
often use global variables, so I'm not even sure what would be the
correct way to do this in Perl.)

Martijn.

Thanks Martijn. Just been discussing this on IRC with Mike. It would seem that I do have to declare each global that I want to use inside each function. Seems daft to me, but I can understand its value... and more importantly, I now know.

I would use Perl but for 2 thing (which are related):
1) Way too many {}; for my liking
2) I don't like Perl. :D

Grant.
-- 
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/listfaq