About Dunder Variables

In Python at a module level, there are a handful of dunder variables - those which start and end with double underscores.

What you can read:

  • __name__ refers to "__main__" if your are running the module directly or to the module name, e.g. "myproject.apps.myapp.models".
  • __doc__ refers to the first docstring of the module.
  • __file__ refers to the absolute path of the *.py file.
  • __cached__ refers to the absolute path of the *.pyc file if the module was imported and not ran directly.
  • __builtins__ refers to the module or dictionary of all builtin variables, functions, and classes.

What you can define by convention:

  • __all__ - the list of variable names that can be imported with from mymodule import *.
  • __version__ - the version of the module.
  • __author__ - the author name.
  • __email__ - the author email.
  • __license__ - the license of the module.

Tips and Tricks Programming Python 3