Package importing question

Daniel Dittmar daniel at dittmar.net
Tue Mar 9 15:16:20 EST 2004


Nick Patavalis wrote:
> so far, so good. Now try:
> 
>   >>> import p0.m0
>   dir(p0.m0)
>   ['__builtins__', '__doc__', '__file__', '__name__', 'f0', 'm1', 'sys']
> 
> fine also! But:
> 
>   >>> dir(p0)
>   ['__builtins__', '__doc__', '__file__', '__name__', '__path__',
>   'm0', 'm1']
> 
> Why on earth does 'm1' show-up there?? And since it does, why doesn't
> 'sys'??

Because all sub modules of package p0 get inserted into the module 
object for p0. This is so that a later import of p0.m1 won't 
import/execute it again. And you did import p0.m1 through the 'import 
m1' in m0.

Daniel



More information about the Python-list mailing list