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.
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to