Re: Same function but different names with different set of default arguments

2016-01-23 Thread Paulo da Silva
Às 07:30 de 21-01-2016, Paulo da Silva escreveu: > Hi all. > > What is the fastest implementation of the following code? > > def g(p): > ... > return something > > def f1(p="p1"): > return g(p) > > def f2(p="p2"): > return g(p) > Thanks to all who responded. I'll try

Re: Same function but different names with different set of default arguments

2016-01-21 Thread Steven D'Aprano
On Thu, 21 Jan 2016 06:30 pm, Paulo da Silva wrote: > Hi all. > > What is the fastest implementation of the following code? Let's find out. Here are three different ways to do it: def g(p): return def f1(p=3): # argument with a default return g(p) def f2(): # no argument at all

Re: Same function but different names with different set of default arguments

2016-01-21 Thread Peter Otten
Paulo da Silva wrote: > Hi all. > > What is the fastest implementation of the following code? > > def g(p): > ... > return something > > def f1(p="p1"): > return g(p) > > def f2(p="p2"): > return g(p) >>> def g(p): return p.upper() ... >>> def f1(): pass ... >>> f1.__code__ = g.__code__ >>>

Re: Same function but different names with different set of default arguments

2016-01-21 Thread Yann Kaiser
Apparently the thread poster cannot receive email, I just received a bounce on my previous email :-/ On Thu, Jan 21, 2016, 08:49 Yann Kaiser wrote: > partial treats keyword arguments as default values, though they become > keyword-only as a result : > > f1 = functools.partial(g, p="p1") > > On T

Re: Same function but different names with different set of default arguments

2016-01-20 Thread Yann Kaiser
partial treats keyword arguments as default values, though they become keyword-only as a result : f1 = functools.partial(g, p="p1") On Thu, Jan 21, 2016, 08:35 Paulo da Silva wrote: > Hi all. > > What is the fastest implementation of the following code? > > def g(p): > ... > ret

Same function but different names with different set of default arguments

2016-01-20 Thread Paulo da Silva
Hi all. What is the fastest implementation of the following code? def g(p): ... return something def f1(p="p1"): return g(p) def f2(p="p2"): return g(p) Thanks Paulo -- https://mail.python.org/mailman/listinfo/python-list