generator expressions: performance anomaly?

Bengt Richter bokr at oz.net
Tue Jan 18 19:18:48 EST 2005


On Tue, 18 Jan 2005 09:24:15 -0500, Steve Holden <steve at holdenweb.com> wrote:
[...]
>You probably already know that sensible compiled language systems have 
>used constant folding since time immemorial, but Python has always 
>eschewed it. That's what comes of being a pragmatist's language: if such 
>optimizations really are required the programmer is expected to perform 
>them.
Which make me wonder what plans there are for providing a better
mechanism than default arguments as a way of initializing local function
variables. Nested def's to create a closure with initialized values is
pretty crufty for that, IMO. Maybe extending the default argument space
with whatever comes after e.g. a triple star delimiter in the argument list,
but which wouldn't be counted as part of the normal arguments? E.g.,

    def foo(x, y=123, *args, **kw, *** i=1, deftime=time.ctime()):
        return x*y, kw.get('which_time')=='now' and time.ctime() or deftime

Seem like a minor extension of the default-arg hack.

Regards,
Bengt Richter



More information about the Python-list mailing list