Suggestions for python 2
Felix Thibault
felixt at dicksonstreet.com
Sat Jan 22 17:22:57 EST 2000
>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).
Felix
More information about the Python-list
mailing list