[Python-ideas] 'where' statement in Python?

Mark Dickinson dickinsm at gmail.com
Sat Jul 24 10:33:36 CEST 2010


Richard Jones (who isn't subscribed to this list, else he'd be sending
this message himself) would like it pointed out that the "withhacks"
module[1] does some things very similar to this (by using bytecode
hackery, IIUC).  See especially the xkwargs and xargs functions.

>>> from withhacks import xkwargs
>>> print(xkwargs.__doc__)
WithHack calling a function with extra keyword arguments.

    This WithHack captures any local variables created during execution of
    the block, then calls the given function using them as extra keyword
    arguments.

        >>> def calculate(a,b):
        ...     return a * b
        ...
        >>> with xkwargs(calculate,b=2) as result:
        ...     a = 5
        ...
        >>> print result
        10

-- 
Mark



More information about the Python-ideas mailing list