generator expressions: performance anomaly?

Stephen Thorne stephen.thorne at gmail.com
Wed Jan 19 08:04:45 CET 2005


On Tue, 18 Jan 2005 23:09:57 -0700, Steven Bethard
<steven.bethard at gmail.com> wrote:
> @with_consts(i=1, deftime=time.ctime())
> def foo(x, y=123, *args, **kw):
>      return x*y, kw.get('which_time')=='now' and time.ctime() or deftime
> 
> Then you don't have to mix parameter declarations with locals definitions.
> 
> [1] I have no idea how implementable such a decorator would be.  I'd
> just like to see function constants declared separate from arguments
> since they mean such different things.

(untested)

def with_constant(**constants_kwargs):  
  def decorator(f)
    def closure(*arg, **kwargs):
      kwargs.update(constants_kwargs)
      return f(*arg, **kwargs)
    return closure
  return decorator
   
Regards,
Stephen Thorne



More information about the Python-list mailing list