Skip to content

Instantly share code, notes, and snippets.

@sabinem
Last active March 4, 2018 08:56
Show Gist options
  • Select an option

  • Save sabinem/0d1f35aa5bd184b38cb4e2a3f26ec5d7 to your computer and use it in GitHub Desktop.

Select an option

Save sabinem/0d1f35aa5bd184b38cb4e2a3f26ec5d7 to your computer and use it in GitHub Desktop.
check_packages_in_python
# check packages in python
# the python packaging is sometimes hard to understand, in that way it often helps to see what python
# thinks about you packages
# (this code is written and tested with python 3.6)
import pkgutil
def inspect_package(name):
"""this will give you:
- the object (also printing out the path of the package
- the submodules (the '*.py' files in your package)
"""
package = name
print(package)
for importer, modname, ispkg in pkgutil.iter_modules(package.__path__):
print("Found submodule %s (is a package: %s)" % (modname, ispkg))
# -------------------- Example ------------------------------------------------
# this is the package we are inspecting -- for example 'datetime' from stdlib
import datetime
inspect_package(datetime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment