pythonic way to optimize access to imported value?

Anton Vredegoor anton at vredegoor.doge.nl
Sat Nov 16 16:39:06 EST 2002


On 16 Nov 2002 16:19:17 GMT, bokr at oz.net (Bengt Richter) wrote:

>Is there no way to do a private throwaway import?

You spared me some time by answering the "homework" issue, I thought I
couldn't let that go, because in the internet culture we live in now
using newsgroups to get questions answered or even complete programs
written or found is given some people the same future shock as the
introduction of the calculator did in times long ago.

Speaking of the  future, I have some code for you that's more on topic
for this thread, I am practically sure it has the same problems as the
other solutions proposed, but it might give you some more handles to
work with. At the moment I am not inclined to check this all out for
you (after all its *your* homework :-) but maybe it has some use, if
not just pretend it was never there.

Regards,
		Anton.

from __future__ import generators

def const():
    import math
    pi = math.pi
    del math
    
    def skippi(x):
        return x-int(x/pi)*pi
    
    d = {"skippi" : skippi}
    
    while 1:
        yield d


def test():
    c = const()
    constants = c.next()
    skippi = constants["skippi"]
    print skippi(3.2)


if __name__=='__main__':
    test()




More information about the Python-list mailing list