[Python-3000] Sky pie: a "var" keyword

Gerrit Holl gerrit at nl.linux.org
Mon Oct 9 17:24:17 CEST 2006


On 2006-10-09 15:47:09 +0200, Jim Jewett wrote:
> Because it is ambiguous.  The print indicates that you want (read)
> access to an existing variable, but the assignment indicates that you
> want (write) access to that variable.  Did you mean
> 
>     x = 0
>     def f():
>         global x  # modify the existing variable
>         print x
>         x = 3
> or
>     x = 0
>     def f():
>         x = x  # shadow the existing variable
>         print x
>         x = 3

I would expect the latter.

However, why global?
What's the use case for having global variables in the first place?
If I want to alter a variable that is not in the current scope, I use a
class:

class Foo:
    x = 0
    def f(self):
        self.x = 3

According to Google codesearch, it is hardly used in the Python library:
http://tinyurl.com/lkhlg
Is global evil?

Just asking.

regards,
Gerrit.


More information about the Python-3000 mailing list