PyMyth: Global variables are evil... WRONG!

Chris Angelico rosuav at gmail.com
Fri Nov 15 23:14:18 EST 2013


On Sat, Nov 16, 2013 at 3:01 PM, Rick Johnson
<rantingrickjohnson at gmail.com> wrote:
> Because when i see code that accesses a variable like this:
>
>     var = value
>
> I have no way of knowing whether the mutation is happening
> to a local variable, a module level variable, or even a true
> global level variable (one which extends beyond the
> containing module).

If it's in a function, and there's no global/nonlocal declaration,
it's local. Otherwise, it's module level. It can't be process-level in
Python, so you don't need to worry about that.

It doesn't get much simpler than that without variable declarations
(in which case it's "scan surrounding scopes till you find a
declaration, that's it" - and it's arguable whether that's simpler or
not). Really Rick, you're clutching at straws here.

ChrisA



More information about the Python-list mailing list