Carl K a écrit :
> Is there a more elegant way of coding this:
>
> x=o.p # save .p
> o.p=0
> o.m()
> o.p=x # restore .p
>
> seems very push/pop to me - like there should be a way that doesn't need
> a var (x) or the save/set lines should be done in one command.
>
> (personally I think .m woul
Steven Bethard wrote:
> Carl K wrote:
>> Is there a more elegant way of coding this:
>>
>> x=o.p # save .p
>> o.p=0
>> o.m()
>> o.p=x # restore .p
>>
>> seems very push/pop to me - like there should be a way that doesn't
>> need a var (x) or the save/set lines should be done in one command.
>
>
On Fri, 2007-04-13 at 14:08 -0500, Carl K wrote:
> Is there a more elegant way of coding this:
>
> x=o.p # save .p
> o.p=0
> o.m()
> o.p=x # restore .p
In Python 2.5, you could leverage the new "with" statement with a
properly crafted context manager along these lines:
"""
from __future__ impo
Carl K wrote:
> Is there a more elegant way of coding this:
>
> x=o.p # save .p
> o.p=0
> o.m()
> o.p=x # restore .p
>
> seems very push/pop to me - like there should be a way that doesn't need
> a var (x) or the save/set lines should be done in one command.
With the appropriate context mange
Is there a more elegant way of coding this:
x=o.p # save .p
o.p=0
o.m()
o.p=x # restore .p
seems very push/pop to me - like there should be a way that doesn't need a var
(x) or the save/set lines should be done in one command.
(personally I think .m would better be implemented by passing in a