[Python-Dev] PEP 328 and PEP 338, redux

Andrew Dalke andrewdalke at gmail.com
Sat Jul 1 11:59:00 CEST 2006


Giovanni Bajo <rasky at develer.com> wrote:
> Real-world usage case for import __main__? Otherwise, I say screw it :)

I have used it as a workaround for timeit.py's requirement that I pass
it strings instead of functions.

>>> def compute():
...     1+1
...
>>> import timeit
>>> t = timeit.Timer("__main__.compute()", "import __main__")
>>> t.timeit()
1.9755008220672607
>>>

You can argue (as many have) that timeit.py needs a better API for
this.  That's a different world than the existing real one.

                                Andrew
                                dalke at dalkescientific.com


More information about the Python-Dev mailing list