Recursive generators and backtracking search
Diez B. Roggisch
deets at nospam.web.de
Sun Oct 30 10:14:48 CET 2005
>> for pos in qsearch( pos ):
>> yield pos
> Um - do you really want to reuse the variable pos here? Yeah, it
> works, but this strikes me as very confusing. I'm not sure that it
> might not be implementation dependent.
Certainly not. pos is - and that is standard python semantics - just a
name. Passing the bound _value_ of pos to some function and rebinding
the the name afterwards is perfectly legal and will work in all
The question of style though remains. I wouldn't do that either, but
what I frequntly do is something like this:
pos = "10"
pos = int(pos)
Thus when I'm sort of transforming a value, I think it's ok, as the name
still refers to the same conceptual entity.
More information about the Python-list