[Python-Dev] locals(), closures, and IronPython...
Greg Ewing
greg.ewing at canterbury.ac.nz
Tue Mar 6 23:30:02 CET 2007
Andrew Dalke wrote:
> def __init__(self, prec=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 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
More information about the Python-Dev
mailing list