scope of function parameters (take two)
Chris Kaynor
ckaynor at zindagigames.com
Tue May 31 16:28:54 EDT 2011
I was thinking you could do something strange like:
kw = {object(): None}
def test(**kw):
print kw
test(**kw)
however, upon testing it (in Python 2.6), I found that it errors while
trying to unpack the kw dict stating that they must all be strings.
Perhaps making a custom class derived off basestring, str, unicode, or bytes
might allow some oddness and possibly slightly worse performance.
Chris
On Tue, May 31, 2011 at 10:10 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Tue, May 31, 2011 at 10:34 AM, Chris Kaynor <ckaynor at zindagigames.com>
> wrote:
> > Is there any reason not to simplify this to:
> > def copy_args(f):
> > @functools.wraps(f)
> > def wrapper(*args, **kw):
> > nargs = copy.deepcopy(args)
> > nkw = copy.deepcopy(kw)
> > return f(*nargs, **nkw)
> > return wrapper
>
> No reason, good call.
>
> > It means you will copy the keys as well, however they will (almost)
> > certainly be strings which is effectively a no-op.
>
> I think the keys will certainly be strings. Is there any scenario
> where they might not be?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110531/77fc4fd2/attachment-0001.html>
More information about the Python-list
mailing list