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: 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 =?utf-8?Q?Guys=F0=9F=98=9C?= 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 Python_Teacher via Python-list 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