On Sat, 18 Dec 2004 14:39:54 -0500, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
> >"Bengt Richter" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] >> On Sat, 18 Dec 2004 03:05:08 -0500, "Terry Reedy" <[EMAIL PROTECTED]> >> wrote: >>>To avoid the redundancy of 'a' and '_a', etc, how about (untested): >>> >>>def dispvia(f): >>> dispatch[f.__name__.split('_')[1]] = f >>> return f > >> That should work. Didn't want to retype ;-) I just wanted to get >> to the experiment following -- did you notice that it takes the >> assignment >> name from each "def dispatch ...", but it is actually re-assigning the >> returned dispatch >> *dict* as the value, not a modified function? > >Yes, I noticed that your second version of dispvia, which I snipped, >returned dispatch instead of the nested function named _. But I did not That's actually not the right "instead" ;-) I.e., the function _ returns dispatch instead of the function passed to _it_ for deco-modification. >quite think thru the import of so doing. > >I think one or more of these recipies might at least be worthy of the >cookbook site so they can be easily referenced in response to future >postings. > It is a little sneaky though, so it might not be prudent to promote without a little more experimentation? I just like to explore ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list