[Tutor] Question about 'scopes'

ahimsa ahimsa@onetel.net.uk
Tue Mar 25 09:00:03 2003


On Tuesday 25 Mar 2003 1:47 pm, alan.gauld@bt.com wrote:

> Its because you are assigning the value to a name. In Python
> that's how you create a new variable. Thus by the act of assignment
> you create a new local variable, that's just how Python works,
> it's the rule.

OK, I'm with you here; one 'declares' an object at the moment of using a=20
variable which is assigned a value, yes?

> When you want to break the normal mode of operation you have to
> explicitly tell Python to ignore the usual rule and use the
> existing global varable.

Since this would deviate from 'normal', under what kinds of conditions mi=
ght=20
one want to declare a variable as a global variable rather than local? Ar=
e=20
there any specific advantages to this? I can understand that there are=20
probably several disadvantages to doing so, such as subtly changing the v=
alue=20
of a global variable in the event of a variable name clash, so what might=
=20
influence someone to declare a variable globally?

<snip: Alan's example>

Thanks again
--=20
News from a diiferent perspective:
http://www.scoop.co.nz
http://www.fromthewilderness.com
____________________________
Prevent digital monopoly:
http://www.againsttcpa.com