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


Groups > comp.lang.python > #96989

Re: A little test for you Guys😜

Path csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!ecngs!feeder2.ecngs.de!217.188.199.168.MISMATCH!takemy.news.telefonica.de!telefonica.de!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; '"""': 0.05; 'subject:test': 0.07; 'wrapper': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.13; '"%s': 0.16; '"hello': 0.16; "'s')": 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; '%s"': 0.22; 'pass': 0.22; 'import': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.26; 'define': 0.27; 'function': 0.28; '**kwargs)': 0.29; '**kwargs):': 0.29; 'preserve': 0.29; 'print': 0.30; 'word.': 0.33; 'message-id:@gmail.com': 0.34; 'handle': 0.34; 'info': 0.34; 'list': 0.34; 'skip:p 30': 0.35; 'should': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'skip:p 20': 0.38; 'to:addr:python.org': 0.40; 'python-list': 0.66; 'subjectcharset:utf-8': 0.71; 'received:89': 0.80; 'f(*args,': 0.84; 'words)': 0.84; 'subject:you': 0.85
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Akira Li <4kir4.1i@gmail.com>
Subject Re: A little test for you Guys😜
Date Tue, 22 Sep 2015 22:48:42 +0300
References <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain
X-Gmane-NNTP-Posting-Host 89.169.229.68
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
Cancel-Lock sha1:VM+r659SR4Ds0XR+0oWgBH4HzNg=
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>
Newsgroups comp.lang.python
Message-ID <mailman.69.1442951315.28679.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1442951315 news.xs4all.nl 23848 [2001:888:2000:d::a6]:35677
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:96989

Show key headers only | 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