This imports the function/class/module _
into the current namespace. So instead of having to type GTG._
, you just have to type _
to use it.
Here is some documentation:
http://docs.python.org/tutorial/modules.html#more-on-modules
It should be noted that you should use this with care. Doing this too much could pollute the current namespace, making code harder to read, and possibly introducing runtime errors. Also, NEVER NEVER NEVER do this:
from MODULE import *
, as it very much pollutes the current namespace.
This technique is most useful when you know you are only going to use one or two functions/classes/modules from a module, since doing this only imports the listed assets.
For example, if I want to use the imap
function from the itertools
module, and I know I won't need any other itertools
functions, I could write
from itertools import imap
and it would only import the imap
function.
Like I said earlier, this should be used with care, since some people may think that
import itertools
# ... more code ...
new_list = itertools.imap(my_func, my_list)
is more readable than
from itertools import imap
# ... more code ...
new_list = imap(my_func, my_list)
as it makes it clear exactly which module the imap
function came from.