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?

From Antoon Pardon <antoon.pardon@rece.vub.ac.be>
Newsgroups comp.lang.python
Subject Re: Is '*args' useful in this example code?
Date 2016-01-05 12:51 +0100
Message-ID <mailman.15.1451994780.2305.python-list@python.org> (permalink)
References <6b0e236f-b240-486d-95e6-17bba9458cde@googlegroups.com>

Show all headers | 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