Custom Search

Thursday, March 5, 2015

Python How to find all submodules of a module

How to find all submodules of module kazoo

>>> import kazoo
>>> import pkgutil

>>>
>>>
>>>
>>> dir(kazoo)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']
>>>
>>>
>>>
>>>#List all submodules of module kazoo
>>> for x in pkgutil.iter_modules(kazoo.__path__):
...     x

...
(, 'client', False)
(, 'exceptions', False)
(, 'handlers', True)
(, 'hosts', False)
(, 'interfaces', False)
(, 'loggingsupport', False)
(, 'protocol', True)
(, 'recipe', True)
(, 'retry', False)
(, 'security', False)
(, 'testing', True)
(, 'tests', True)
>>>
>>>
>>>
>>> kazoo.client
Traceback (most recent call last):
  File "", line 1, in
AttributeError: 'module' object has no attribute 'client'
>>>
>>>
>>>
>>> import kazoo.client
>>> import kazoo.exceptions
>>> import kazoo.handlers

>>>
>>>

OR



>>>#List all submodules of module kazoo
>>> for x in pkgutil.walk_packages(kazoo.__path__):
...     x

...
(, 'client', False)
(, 'exceptions', False)
(, 'handlers', True)
(, 'hosts', False)
(, 'interfaces', False)
(, 'loggingsupport', False)
(, 'protocol', True)
(, 'recipe', True)
(, 'retry', False)
(, 'security', False)
(, 'testing', True)
(, 'tests', True)
>>>
>>>
>>>

1 comment:

  1. How to install Install Pygame

    #sudo apt-get update --fix-missing
    #sudo apt-get build-dep python-pygame
    #sudo apt-get install mercurial
    #hg clone https://bitbucket.org/pygame/pygame
    #cd pygame
    #sudo python setup.py install

    #virtualenv venv --system-site-packages
    #source venv/bin/activate
    #python -c "import pygame"

    ReplyDelete