Alex Rivera | Logout

What is the difference between import modx and from modx import *?

Asked 2011-02-26T00:38:46.673
25

If I were to import some module called modx, how would that be different from saying

from modx import *

Wouldn't all the contents be imported from each either way? This is in python just to clarify.

Edit
Report

1 Answer

19

If a defines a.b and a.c...

import a
a.b()
a.c()

vs.

from a import b
b()
c() # fails because c isn't imported

vs.

from a import *
b()
c()

Note that from foo import * is generally frowned upon since:

  1. It puts things into the global namespace without giving you fine control
  2. It can cause collisions, due to everything being in the global namespace
  3. It makes it unclear what is actually defined in the current file, since the list of what it defines can vary depending on what's imported.
answered 2011-02-26T00:47:42.167

Your Answer