[Tutor] Iterable Understanding
Kent Johnson
kent37 at tds.net
Mon Nov 16 04:01:44 CET 2009
On Sun, Nov 15, 2009 at 8:57 PM, Marc Tompkins <marc.tompkins at gmail.com> wrote:
> On Sun, Nov 15, 2009 at 4:11 PM, Stephen Nelson-Smith <sanelson at gmail.com>
> wrote:
>>
>> > import gzip
>> > from heapq import heappush, heappop, merge
>>
>> Is this a preferred method, rather than just 'import heapq'?
>>
> It has a couple of advantages:
...
> - efficiency: you import only what you actually need to use. Importing all
> of a gigantic package to use one or two methods is wasteful;
I can't think of any way in which
import heapq
is "wasteful" compared to
from heapq import heappush, heappop, merge
other than a tiny efficiency in name lookup (it's faster to lookup
just heappush than heapq.heappush).
In either case, the entire module is loaded. The only difference is in
which names are introduced into the importing module's namespace.
Kent
More information about the Tutor
mailing list