Python Package - init .py

Card Puncher Data Processing

About

A regular package is typically implemented as a directory containing an __init__.py file.

The __init__.py file is tells Python that you can use the folder to import a module. (The default behavior is no import).

When a regular package is imported, this __init__.py file is implicitly executed, and the objects it defines are bound to names in the package’s namespace.

The __init__.py file can contain the same Python code that any other module can contain.

The __init__.py mechanism is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur later on the module search path.

In the simplest case, __init__.py can just be an empty file, but it can also:

  • execute initialization code for the package
  • or set the all variable

all

The __all__ variable define a list of module to import when using the package import * statement. See Python Package - Import It defines an explicit index of the package.

Example:

__all__ = ["echo", "surround", "reverse"]





Discover More
Card Puncher Data Processing
Language - (Import|Include|Require)

import basically makes names (generally of function) available to the current script. To load modules, language uses different expression: imports includes. require (Node) The import functionality...
Card Puncher Data Processing
Python - Main (Entry Point)

In Python. In the . Example: To provide executable scripts,...
Card Puncher Data Processing
Python - Regular Package

A regular package is a directory containing an init file. Package can be installed via distribution package. See distribution package installation. See Their location can be chosen during...
Python Build Artifact Setup Py
Python - Regular Package (Shipping | Packaging)

and in Python How to release regular package adapted from (they are using the setuptools framework) With python 3. where: setup.py...
Card Puncher Data Processing
Python Package - Import

import functionality in Python In order to use the names (generally, variable and function definitions) defined in a module, you must either: import the module itself or import the specific definitions,...



Share this page:
Follow us:
Task Runner