doctest environment question

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue May 22 05:11:36 EDT 2007


En Tue, 22 May 2007 04:21:06 -0300, tag <thomas.guest at gmail.com> escribió:

> Here's a function which rebinds a function at the top level of a
> module (it won't work for nested functions).
>
>>>> def announce_function(f):
> ...     " Rebind f within a module so that calls to f are announced. "
> ...     import inspect
> ...     setattr(inspect.getmodule(f), f.__name__, announce(f))
>
> Let's give it a try. This next works fine in an interactive Python
> session but fails when doctested.

The version given by Peter Otten may do what you want, but I'd consider if  
you really need an announce_function in the first place, given all the  
other ways you already have to do the same thing.
Implicitely rebinding globals does not look good.

-- 
Gabriel Genellina




More information about the Python-list mailing list