[Tutor] Question on "import foobar" vs "from foobar import *"
Alan Gauld
alan.gauld at btinternet.com
Sat Jan 9 16:21:59 CET 2010
"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.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list