[Numpy-discussion] Numpy and PEP 343

Tim Hochberg tim.hochberg at cox.net
Tue Feb 28 15:20:03 EST 2006


Tim Hochberg wrote:


[SNIP]

Ugh. This last part got mangled somehow.

>
>
> [1] Here's an example that fakes with and tests deferral:
>
>
>
> import sys
>
> class deferral:
>    frames = set()
>    def __enter__(self):
>        self.frame = sys._getframe(1)
>        self.frames.add(self.frame)
>    def __exit__(self, *args):
>        self.frames.discard(self.frame)
>        self.frame = None
>         def should_defer():
>    return (sys._getframe(1) in deferral.frames)
>     

[This got all jammed together, sorry]

> def f(n):
>    if not n:
>        return
>    if n % 4:
>        print "should_defer() =", should_defer(), "for n =", n
>        f(n-1)
>    else:
>        # This is a rough translation of:
>        # with deferral():
>        #    print "should_defer() =", should_defer(), "in f"
>        #    g(n-1)
>        d = deferral()
>        d.__enter__()
>        try:
>            print "should_defer() =", should_defer(), "for n =", n
>            f(n-1)
>        finally:
>            d.__exit__(None, None, None)
>
>
> f(10)
>
>
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting 
> language
> that extends applications into web and mobile media. Attend the live 
> webcast
> and join the prime developer group breaking into this new coding 
> territory!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>
>






More information about the NumPy-Discussion mailing list