[Tutor] Iterable Understanding
Marc Tompkins
marc.tompkins at gmail.com
Mon Nov 16 02:57:41 CET 2009
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:
- 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091115/b00db83b/attachment.htm>
More information about the Tutor
mailing list