attribute save restore

2007-04-13 Thread Carl K
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

Re: attribute save restore

2007-04-13 Thread Steven Bethard
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

Re: attribute save restore

2007-04-13 Thread Carsten Haese
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

Re: attribute save restore

2007-04-13 Thread Carl K
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. > >

Re: attribute save restore

2007-04-13 Thread Bruno Desthuilliers
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