Rebindings [was Re: Favorite non-python language trick?]

Steven D'Aprano steve at REMOVETHIScyber.com.au
Sun Jun 26 06:36:42 CEST 2005


On Sat, 25 Jun 2005 23:08:10 +0000, Bengt Richter wrote:

>>Using := and = for assignment and equality is precisely as stupid as using
>>= and == for assignment and equality. Perhaps less stupid: why do we use
>>== for equals, but not ++ for plus and -- for minus?
>>
> I agree, but I think := would be nice in python for RE-binding an existing
> binding, wherever it is seen from the local context. Thus you could
> write
> 
>     def foo(): x:=123
> 
> and
>    x = 456
>    def bar():
>        x = 789
>        foo()  # finds and rebinds local x
>        print x
>    bar() # -> 123
>    print x # -> 456
>    foo()      # finds and rebinds the global x
>    print x # -> 123
> 
> but
>    del x
>    foo()  #-> NameError exception, can't find any x to rebind
> 
> hm, wandered a bit OT there, ;-/

Given how much the use of global variables are discouraged, is it a
good idea to allow even more inter-namespace interactions?


-- 
Steven.




More information about the Python-list mailing list