Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'args': 0.04; 'modify': 0.05; "'')": 0.07; 'args)': 0.07; 'arguments': 0.07; 'wrapper': 0.07; 'arg': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:using': 0.09; 'wraps': 0.09; 'def': 0.10; 'functools': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'tempted': 0.16; 'y):': 0.16; 'wrote:': 0.17; 'import': 0.21; 'simpler': 0.22; 'header:User-Agent:1': 0.26; 'header:X -Complaints-To:1': 0.28; 'post': 0.28; 'subject:all': 0.29; 'function': 0.30; 'to:addr:python-list': 0.33; 'subject:?': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'subject:there': 0.65; 'subject:before': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Is there a simpler way to modify all arguments in a function before using the arguments? Date: Sat, 10 Nov 2012 10:09:08 +0100 Organization: None References: <18134e77-9b02-4aec-afb0-794ed900d194@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084b88e.dip.t-dialin.net User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352538537 news.xs4all.nl 6923 [2001:888:2000:d::a6]:56517 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33080 Miki Tebeka wrote: >> Is there a simpler way to modify all arguments in a function before using >> the arguments? > You can use a decorator: > > from functools import wraps > > def fix_args(fn): > @wraps(fn) > def wrapper(*args): > args = (arg.replace('_', '') for arg in args) > return fn(*args) > > return wrapper > > @fix_args > def foo(x, y): > print(x) > print(y) I was tempted to post that myself, but he said /simpler/ ;)