Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:two': 0.07; 'wrapper': 0.07; 'be:': 0.09; 'subject:parameters': 0.09; 'def': 0.12; 'am,': 0.14; 'wrote:': 0.14; '*args,': 0.16; 'arg': 0.16; 'nargs': 0.16; 'subject:function': 0.16; '\xa0for': 0.16; 'argument': 0.16; 'tue,': 0.17; 'keyword': 0.19; 'cheers,': 0.19; 'work,': 0.20; 'header:In-Reply-To:1': 0.21; 'received:209.85.161.46': 0.23; 'received:mail- fx0-f46.google.com': 0.23; 'library.': 0.25; 'function': 0.25; 'received:209.85.161': 0.26; 'message-id:@mail.gmail.com': 0.28; 'version': 0.29; 'module': 0.30; 'args)': 0.30; 'email name:': 0.30; 'named': 0.32; 'skip:\xa0 30': 0.32; 'to:addr:python-list': 0.33; 'break': 0.33; 'skip:" 20': 0.33; 'daniel': 0.34; 'there': 0.35; '8bit%:3': 0.35; 'module.': 0.35; 'usual': 0.35; 'received:google.com': 0.37; 'received:209.85': 0.37; 'third- party': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'subject: (': 0.39; 'received:209': 0.39; 'to:addr:python.org': 0.39; '31,': 0.65 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type:content-transfer-encoding; bh=NsrWcq/TCWGoUGPyHXi5IANMFfjNL2hP9C5V0WmD88w=; b=mTvTGCRuQyruUiOYV/VlvychT09WhTe99OEjuSIFNMTfFVYSG3LrdWLAtVIevMNdmk zJKDBXpfDyFpusjE7kx2c55tIMM+9lUC8oSgU1xO/yqqWnGLqyE8Gpwdz6UXZkfwmWaO HcLUv3uT76YpyP6l9Ls6XBqST742WlBk5e21U= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=U2WekW4RTkdw6iAcHcSH807mlHQHd58m4xewBfA58qVeB8tgheWyPIgiEE3Jcghv6G PWGlfcO9bYlHPl+JwrArAAVOCFQAYpmdermePzWQe2X/SwdXDz5W5C3ZF0u2lDiLEFV/ sZfeu8jCOsRklOQ1YV5+vFYbL7uesMtMMLnw8= MIME-Version: 1.0 In-Reply-To: References: <6699AB10-988A-49AD-B7C1-6BAA2CC3D008@mcgill.ca> From: Ian Kelly Date: Tue, 31 May 2011 10:16:12 -0600 Subject: Re: scope of function parameters (take two) To: Python Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 28 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1306858604 news.xs4all.nl 49178 [::ffff:82.94.164.166]:54310 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6737 On Tue, May 31, 2011 at 1:38 AM, Daniel Kluev wrote: > @decorator.decorator > def copy_args(f, *args, **kw): > =A0 =A0nargs =3D [] > =A0 =A0for arg in args: > =A0 =A0 =A0 =A0nargs.append(copy.deepcopy(arg)) > =A0 =A0nkw =3D {} > =A0 =A0for k,v in kw.iteritems(): > =A0 =A0 =A0 =A0nkw[k] =3D copy.deepcopy(v) > =A0 =A0return f(*nargs, **nkw) There is no "decorator" module in the standard library. This must be some third-party module. The usual way to do this would be: def copy_args(f): @functools.wraps(f) def wrapper(*args, **kw): nargs =3D map(copy.deepcopy, args) nkw =3D dict(zip(kw.keys(), map(copy.deepcopy, kw.values()))) return f(*nargs, **nkw) return wrapper Note that this will always work, whereas the "decorator.decorator" version will break if the decorated function happens to take a keyword argument named "f". Cheers, Ian