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:
-  convenience: if you "import heapq", then to do a push you need to type
"heapq.heappush"; if you do "from heapq import heappush", then you can
simply type "heappush" to use it.
-  efficiency: you import only what you actually need to use.  Importing all
of a gigantic package to use one or two methods is wasteful; on the other
hand, if a package contains five methods and you're using four of them, this
might not be such a big deal.
Remember, this is Python... there's always going to be more than one way to
do it, and you'll get an argument on this list for every one of them.

What you should NEVER do, though: "from package import *"
-- 
www.fsrtechnologies.com
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to