Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #101268

Re: Is '*args' useful in this example code?

Path csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed0.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail
From Antoon Pardon <antoon.pardon@rece.vub.ac.be>
Newsgroups comp.lang.python
Subject Re: Is '*args' useful in this example code?
Date Tue, 5 Jan 2016 12:51:52 +0100
Lines 38
Message-ID <mailman.15.1451994780.2305.python-list@python.org> (permalink)
References <6b0e236f-b240-486d-95e6-17bba9458cde@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de /Xhus86mFsVqWrP7cCjLnwvj6TU8URN2LWzjBzF3jKmw==
Return-Path <antoon.pardon@rece.vub.ac.be>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.012
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'args': 0.04; 'received:134': 0.05; "subject:' ": 0.07; 'subject:code': 0.07; '*args': 0.09; 'def': 0.13; 'b):': 0.16; 'received:ac.be': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'weird.': 0.16; 'code.': 0.23; 'thanks,': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'example': 0.26; '**kwargs)': 0.29; '**kwargs):': 0.29; 'code:': 0.29; 'print': 0.30; 'code': 0.30; 'received:be': 0.30; 'wrap': 0.33; 'but': 0.36; 'to:addr:python- list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'hi,': 0.38; 'to:addr:python.org': 0.40; 'your': 0.60; 'here': 0.66; 'link:': 0.69; 'func(*args,': 0.84; 'pardon': 0.84; 'schreef': 0.84; 'subject:this': 0.85
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result AgAGAD2ti1aGuA9G/2dsb2JhbABehAxHASaIWLVWIoVtAoFnAQEBAQEBhUABAQQjVRELGgIFFgsCAgkDAgECAUUTCAKIKw6wKo5Ygi0BAQgCIYEBhVWEf4UjglCBSQWXCIVCiBGBXEqGdYViik6Dc2SEC4YBAQEB
User-Agent Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Icedove/38.5.0
In-Reply-To <6b0e236f-b240-486d-95e6-17bba9458cde@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:101268

Show key headers only | View raw


Op 05-01-16 om 03:16 schreef Robert:
> Hi,
>
> I find an example code on wrap at this link:
> http://stackoverflow.com/questions/308999/what-does-functools-wraps-do
>
> Here is the code:
> ////////
> def logged(func):
>     def with_logging(*args, **kwargs):
>         print func.__name__ + " was called"
>         return func(*args, **kwargs)
>     return with_logging
> ///////
>
> I understand now, but I feel the args usage is weird. I don't see any way 
> to use *args and **kwargs in above code. What is your opinion on it?
>
>
> Thanks,

You want the following to work

def add(a, b):
    return a + b

def double(n)
    return n + n

logged_add = logged(add)
logged_double = logged(double)

s = logged_add(3, 5)
d = logged_double(13)

-- 
Antoon Pardon

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Is '*args' useful in this example code? Robert <rxjwg98@gmail.com> - 2016-01-04 18:16 -0800
  Re: Is '*args' useful in this example code? Ben Finney <ben+python@benfinney.id.au> - 2016-01-05 13:26 +1100
    Re: Is '*args' useful in this example code? Robert <rxjwg98@gmail.com> - 2016-01-04 18:34 -0800
      Re: Is '*args' useful in this example code? Ben Finney <ben+python@benfinney.id.au> - 2016-01-05 14:28 +1100
        Re: Is '*args' useful in this example code? Robert <rxjwg98@gmail.com> - 2016-01-05 05:04 -0800
  Re: Is '*args' useful in this example code? Arif Khokar <akhokar1234@wvu.edu> - 2016-01-04 22:29 -0500
  Re: Is '*args' useful in this example code? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-01-05 12:51 +0100

csiph-web