Context manager to temporarily change the variable of a register [aka write swap(a,b)]
Diez B. Roggisch
deets at nospam.web.de
Tue Aug 25 22:25:31 CEST 2009
Evan Driscoll schrieb:
> On Aug 25, 2:33 pm, Evan Driscoll <eva... at gmail.com> wrote:
>> I want to make a context manager that will temporarily change the
>> value of a variable within the scope of a 'with' that uses it. This is
>> inspired by a C++ RAII object I've used in a few projects. Ideally,
>> what I want is something like the following:
> Okay, so I think I actually got this with some consultation with a
> friend. Critiques?
Modifying locals isn't really allowed - it might stop working with
certain implementations of python.
And to be honest - I don't really see a use-case for your whole
approache. Why don't you want to introduce a new name?
More information about the Python-list