mod_python exception catching, other repetitious per-page actions

Karl A. Krueger kkrueger at example.edu
Fri Mar 26 15:25:06 EST 2004


Jeff Epler <jepler at unpythonic.net> wrote:
> page_wrapper() could do extra magic with exec if you want it to have the
> same signature as callable.. something like
>    def page_wrapper(callable):
>        d = {}
>        name = callable.__name__
>        argspec = getargspecstr(callable) # based on inspect.getargspec()
>        callspec = ... # argspec with default values removed
>        exec """def %s(%s): ... return callable(%s) ...""" \
>            % (name, argspec, callspec) in d
>        return d[name]
> ... barf, eh?

Barf?  I -did- say I kind of wanted a Lisp macro; exec is about as close
as Python can get, I suppose.

Anyway, this has given me useful thoughts.  Of course, I may just end up
back with keyword arguments.  :-/

(But probably -not- reimplementing my whole application in Lisp.  I'm
not that good in Lisp yet.)

-- 
Karl A. Krueger <kkrueger at example.edu>
Woods Hole Oceanographic Institution
Email address is spamtrapped.  s/example/whoi/
"Outlook not so good." -- Magic 8-Ball Software Reviews



More information about the Python-list mailing list