You can also import a module *as* another name.
So you can import foo as f and then invoke all of
foo's methods and access all of foo's members using
just f.method() and f.member
This should not be used for abbreviation (configure
your text editor with abbreviations if you want them) but
can be used to avoid namespace collisions. You can actually
work with two different foo modules, importing one as "foo"
and the other as "foo2" or "foobar" (or whatever).
It's also worth pointing out that you can bind a variable
to a method or member:
import Foo
a=Foo.foo()
method=Foo.method()
print a.method()
... which can help in cases where you want to instantiate
and object in a class defined by Foo, and perform a number
of Foo's static methods on one or more of your objects.
(The curses module comes to mind). In many cases you can
use the local variables to make your code readable (using
better identifiers than my example) by eliminating all
those repetitive Foo.this() and Foo.that() explicit
references.
Of course, like operator overloading, and many other
OO features (and the infamous #define in C) it's also
possible, even easy to overuse these features making
your code so idiosyncratic as to completely obscure its
intent from future maintainers (including your, hopefully
wiser, self in years to come).
It might be worth mentioning here that * can be used to import all modules.
A common gotcha for beginners is when loading a simple script the file extention isn't used.
ie.
import script1
not
import script1.py
The resulting error message isn't very obvious.
As another poster said ...
"... can be a list of names seperated by commas or the '*' operator to indicate that all definitions should be imported. This is not always safe because of the potential for overlapping namespaces, so explicitly naming the items to be imported is recommended.
"Simply using 'import module' has a similar wildcard effect in that all items in 'module' can be used with the '.' operator;
import foo
foo.bar() # foo includes function 'bar'"
... which can help in cases where you want to instantiate
and object in a class defined by Foo, and perform a number
=>"an object"
import has confused me when using the IDLE. can you clarify- is there no way to reload a class while running IDLE? I know you can reload a module easily enough. I can find nothing in 'Learning Python' or python.org on this.