Python - How To in Python

ID : 164

viewed : 94

Tags : PythonPython Package

vote vote


In Python, there are two types of packages named regular packages and namespace packages. The Regular packages exist in Python 3.2 and previous versions. These packages are used as a directory that contains the file, which is implicitly called or executed.

The file in Python lets the Interpreter knows that a directory contains a Python code in the module. This file can have the same code as any other Python module.

Files named as are used to flag directories as Python packages.

For example,

mydir/spam/ mydir/spam/ 

If this file is removed, Python can not search for submodules in the directory, leading to failure in importing the module.

Main Reasons to Use in Python

your_package/     ... 
  1. Using will help in initializing some details like logging at the top.
import logging.config logging.config.dictConfig(Your_logging_config) 
  1. helps in easing the import of files. A function fn() can be imported from a file when it is in a package.
from filename import fn() 

  • Related HOW TO?