Suggestions for python 2
Michael Hudson
mwh21 at cam.ac.uk
Sat Jan 22 17:26:01 EST 2000
Felix Thibault <felixt at dicksonstreet.com> writes:
> >In article <000501bf623e$18b56a20$9a2d153f at tim>,
> >Tim Peters <tim_one at email.msn.com> wrote:
> >>[Evan Simpson]
> >>>
> >>> I rather like the idea of having to explicitly bring names
> >>> into an inner scope,
> >>
> >>Me too -- except in the cases that bite most often, where a trivial little
> >>lambda wants to refer to one or two measly little names from its context.
> >>People stumble on that so often it's a FAQ.
> >
>
> How hard would it be to implement something like:
>
> def like_a_list(*now_args):
> def return_func(!now_args, *later_args, **show):
> if show:
> return list(now_args+later_args)
> else:
> return apply(like_a_list, now_args + later_args)
> return return_func
>
> where the ! (or whatever) means something like this happens:
>
> def like_a_list(*now_args):
> """like_a_list(value0, value1,...) store some values in a function"""
> fun_str = """def return_func(*later_args, **show):
> now_args = %s
> if show:
> return list(now_args+later_args)
> else:
> return apply(like_a_list, now_args + later_args)\n"""\
> % (now_args,)
> exec(fun_str)
> return return_func
>
> when the inner function is defined ? (Except that it works when
> eval(repr(object)) doesn't and it's not as ugly).
I don't really understand what you are trying to do, but you are
invited to check out xapply.py in my bytecodehacks package which can
be found at
http://starship.python.net/crew/mwh/
and is documented here:
http://starship.python.net/crew/mwh/bch/module-bytecodehacks.xapply.html
If that isn't what you're after, can you post an example of what you
might want to do with this hypothetical function? I can probably whip
something up for you.
Cheers,
Michael
More information about the Python-list
mailing list