Possible Duplicate:
Should I use "from package import utils, settings" or "from . import utils, settings"
What are the guidelines about the choice between the following when importing from the python standard library?:
import foo
from foo import bar
What are the considerations? Is it a footprint thing? Or just a potential name clash thing?
If a module had minimal string handling, would this be going too far?:
from string import split
If a program has several modules, will results of an import done by one module be usable by subsequent modules in the program?
If an imported module is only required in cold code, is it considered good form to have that import buried inside the logic block containing the cold code?
If you use pyflakes, it will complain if you don’t use things that you have imported.
I find, if I only need one or two functions/classes, then I’ll import them directly: if I need lots, I may just use the namespaced version (
foo.bar).There is a cost to . lookups, so if you had lots of them in a nested loop, it may be better to import the function directly, or you could rebind the function to a local name.
To reduce lookup time: