Proposal: Inline Import
kent at kentsjohnson.com
Sat Dec 10 03:03:15 CET 2005
Shane Hathaway wrote:
> Mike Meyer wrote:
>> Shane Hathaway <shane at hathawaymix.org> writes:
>>> That syntax is verbose and avoided by most coders because of the speed
>> What speed penalty? "import re" is a cheap operation, every time but
>> the first one in a program.
> I'm talking about using imports *everywhere*. The penalty would be
Have you tried it?
D:\Projects\CB>python -m timeit -s "import re" "import re"
1000000 loops, best of 3: 1.36 usec per loop
You need a lot of imports before 1 usec becomes "appreciable". And your
proposal is doing the import anyway, just under the hood. How will you
avoid the same penalty?
More information about the Python-list