def walk_packages(path=None, prefix='', onerror=None):
 def seen(p, m={}):
  if (p in m):
   return True
  m[p] = True
 for (importer, name, ispkg) in iter_modules(path, prefix):
  (yield (importer, name, ispkg))
  if ispkg:
   try:
    __import__(name)
   except ImportError:
    if (onerror is not None):
     onerror(name)
   except Exception:
    if (onerror is not None):
     onerror(name)
    else:
     raise
   else:
    path = (getattr(sys.modules[name], '__path__', None) or [])
    path = [p for p in path if (not seen(p))]
    for item in walk_packages(path, (name + '.'), onerror):
     (yield item)

def walk_packages ( path = None , prefix = '' , onerror = None ) : def seen ( p , m = { } ) : if ( p in m ) : return True m [ p ] = True for ( importer , name , ispkg ) in iter_modules ( path , prefix ) : ( yield ( importer , name , ispkg ) ) if ispkg : try : __import__ ( name ) except ImportError : if ( onerror is not None ) : onerror ( name ) except Exception : if ( onerror is not None ) : onerror ( name ) else : raise else : path = ( getattr ( sys . modules [ name ] , '__path__' , None ) or [ ] ) path = [ p for p in path if ( not seen ( p ) ) ] for item in walk_packages ( path , ( name + '.' ) , onerror ) : ( yield item )
yields for all modules recursively on path .