Package importing question

Nick Patavalis npat at efault.net
Tue Mar 9 16:58:01 CET 2004


Assume this package:

  p0/
    __init.py__  <-- empty
    m0.py
    m1.py

  $ cat p0/m0.py
  import sys
  import m1
  def f0(i):
    pass

  $ cat p0/m1.py
  def f0(i):
    pass

Now let's see what happens when importing the package:

  $ python2.3 
  ........
  >>> import p0
  >>> dir(p0)
  ['__builtins__', '__doc__', '__file__', '__name__', '__path__']

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'??

Thanks in advance
/npat



More information about the Python-list mailing list