[Tutor] Question on "import foobar" vs "from foobar import *"
lowelltackett at yahoo.com
Sat Jan 9 17:35:45 CET 2010
If I might offer one small comment...
It seems to me that this argument also goes to a code readability issue; ergo, if you choose "from foobar..." as opposed to "import foobar", then from that point on you only need employ foobar's methods in your code, and they are not alway easily recognizable. i.e, by importing foobar, you will always prefix a method with its' parent module name, which [I think] makes the code more understandable.
>From the virtual desk of Lowell Tackett
--- On Sat, 1/9/10, Alan Gauld <alan.gauld at btinternet.com> wrote:
From: Alan Gauld <alan.gauld at btinternet.com>
Subject: Re: [Tutor] Question on "import foobar" vs "from foobar import *"
To: tutor at python.org
Date: Saturday, January 9, 2010, 10:21 AM
"Rob Cherry" <pythontutor at lxrb.com> wrote
> Extending on this advice somewhat - is it *ever* correct to "import foobar".
Yes, it is *usually* correct to "import foobar" and rarely correct to "from foobar".
The exception being if you only need one or two names from foobar, but
usually you need a lot more, in which case use import foobar.
To save typing you can give foobar a shorter name:
import foobar as fb
For some reason that convenience feature doesn't get mentioned
all that often but I use it a lot.
-- Alan Gauld
Author of the Learn to Program web site
Tutor maillist - Tutor at python.org
To unsubscribe or change subscription options:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor