On Sun, Nov 15, 2009 at 8:57 PM, Marc Tompkins <marc.tompk...@gmail.com> wrote:
> On Sun, Nov 15, 2009 at 4:11 PM, Stephen Nelson-Smith <sanel...@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
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to