[Python-Dev] locals(), closures, and IronPython... (original) (raw)
Greg Ewing greg.ewing at canterbury.ac.nz
Tue Mar 6 23:30:02 CET 2007
- Previous message: [Python-Dev] locals(), closures, and IronPython...
- Next message: [Python-Dev] locals(), closures, and IronPython...
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Andrew Dalke wrote:
def init(self, prec=None, rounding=None, traps=None, flags=None, roundingdecision=None, Emin=None, Emax=None, capitals=None, clamp=0, ignoredflags=None): ... for name, val in locals().items(): if val is None: setattr(self, name, copy.copy(getattr(DefaultContext, name))) else: setattr(self, name, val)
Hmmm. For things like that, maybe what you really want is to be able to give the ** arg a default value:
def init(self, **kwds = dict(rec=None, rounding=None, traps=None, flags=None, _rounding_decision=None, Emin=None, Emax=None, capitals=None, _clamp=0, _ignored_flags=None)) for name, val in kwds: ...
Although you can get a similar effect now by doing
def __init__(self, **kwds):
args = dict(prec=None, rounding=None,
traps=None, flags=None,
_rounding_decision=None,
Emin=None, Emax=None,
capitals=None, _clamp=0,
_ignored_flags=None)
args.update(kwds)
for name, value in args:
...
So, no need for locals() here.
-- Greg
- Previous message: [Python-Dev] locals(), closures, and IronPython...
- Next message: [Python-Dev] locals(), closures, and IronPython...
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]