[Python-ideas] binding vs rebinding

Arnaud Delobelle arnodel at googlemail.com
Sun Feb 8 08:34:57 CET 2009

[Redirecting to python-ideas]

2009/2/8 Bruce Leban <bruce at leapyear.org>:
> On Sat, Feb 7, 2009 at 11:16 PM, Arnaud Delobelle <arnodel at googlemail.com>
> wrote:
>> 2009/2/8 Bruce Leban <bruce at leapyear.org>:
>> > There *is* something in Python related to this that I find obviously
>> > different and that's local and global variables. I would prefer that all
>> > global variables have to be included in a global declaration. I dislike
>> > the
>> > fact that an assignment to a variable changes other references to that
>> > same
>> > name from local to global references. This sort of feels like "spooky
>> > action
>> > at a distance" to me.
>> IMHO it would be very tiresome to have to declare all global functions
>> and builtins used in a function as global E.g.
>> def foo(x):
>>    return x + 2
>> def bar(x):
>>    global str, foo, int
>>    return str(foo(int(x)))
> I don't want it for functions, just for variables. I realize that those may
> be the same on some level but I don't think fo them that way when I'm
> writing code.

That's impossible.  Functions are python objects which are bound to
variables at runtime.  At compile time (when it has to be decided
which variable is local and which is local), there is no way to know
if a variable will be bound to a function or to another object.
Worse, many python objects are callable without being functions.


More information about the Python-ideas mailing list