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


Groups > comp.lang.python > #96989

Re: A little test for you Guys😜

From Akira Li <4kir4.1i@gmail.com>
Subject Re: A little test for you Guys😜
Date 2015-09-22 22:48 +0300
References <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.69.1442951315.28679.python-list@python.org> (permalink)

Show all headers | View raw


Python_Teacher via Python-list <python-list@python.org> writes:

...
> Let's define the function plural :
>
> def plural(words):
>     plurals = []
>     for word in words:
>        plurals.append(word + 's')
>     return plurals
>
> for word in plural(['cabagge','owl','toy']):
>     print word

plural() should accept a single word. To handle list of words, call
map(plural, words)

...
> def str2print(f):
>     def str2print_wrap(*args, **kwargs):
>         """wrapper"""
>         s = f(*args, **kwargs)
>         print s
>    return str2print_wrap
>
> def hello(s):
>     """ Return "Hello $s" """
>     return "%s %s" % ("Hello", s)

Use functools.wraps() to preserve the function info for introspection:

  import functools
  
  def prints_result(function):
      @functools.wraps(function)
      def wrapper(*args, **kwargs):
          result = function(*args, **kwargs)
          print(result)
          return result #XXX return
      return wrapper
  
  @prints_result
  def hello(...):
      pass

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


Thread

A little test for you Guys😜 Python_Teacher <ljfc2000@yahoo.com> - 2015-09-22 11:43 -0700
  Re: A little test for you Guys😜 Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-22 13:14 -0600
  Re: A little test for you Guys😜 "Sven R. Kunze" <srkunze@mail.de> - 2015-09-22 21:42 +0200
  Re: A little test for you Guys😜 Akira Li <4kir4.1i@gmail.com> - 2015-09-22 22:48 +0300
  Re: A little test for you Guys😜 James Harris <james.harris.1@gmail.com> - 2015-09-22 13:28 -0700
  Re: A little test for you Guys😜 sohcahtoa82@gmail.com - 2015-09-22 14:18 -0700
    Re: A little test for you Guys😜 "James Harris" <james.harris.1@gmail.com> - 2015-09-22 22:31 +0100
    Re: A little test for you Guys😜 Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-22 15:33 -0600
    Re: A little test for you Guys😜 Lj Fc <ljfc2000@yahoo.com> - 2015-09-22 15:21 -0700
  Re: A little test for you Guys😜 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-23 00:32 +0100
  Re: A little test for you Guys😜 Chris Angelico <rosuav@gmail.com> - 2015-09-23 09:45 +1000
  Re: A little test for you Guys😜 MRAB <python@mrabarnett.plus.com> - 2015-09-23 00:56 +0100
    Re: A little test for you Guys😜 alister <alister.nospam.ware@ntlworld.com> - 2015-09-23 18:06 +0000
  Re: A little test for you Guys😜 Christian Gollwitzer <auriocus@gmx.de> - 2015-09-23 08:26 +0200

csiph-web