newbie question: getting a module in a package

Jim Althoff jima at aspectdv.com
Wed Sep 22 19:56:30 EDT 1999


FAQ 4.85 suggests the following for
importing a module in a package 
(s = "x.y.z"):

m = __import__(s)

for i in string.split(s, ".")[1:]:
    m = getattr(m, i)


Doesn't the following work equally well?
(And is more obvious and faster?)

__import__(s)
m = sys.modules[s]

Perhaps I'm missing something?

Jim





More information about the Python-list mailing list