python modules - ghdrako/doc_snipets GitHub Wiki

import sys
ss.path   - wyswietla liste sciezek gdzie python szuka pakitow. Ma pierwszym miejscu jest biezacy katalog.

module - is a single file (or files) that are imported under one import and used. e.g.

import my_module

package - is a collection of modules in directories that give a package hierarchy.

from my_package.timing.danger.internets import function_of_love

Package is just a module with a __path__ attribute.They are just packaged up differently; they are formed by the combination of a directory plus __init__.py file. They are modules that can contain other modules

When you import a package, only variables/functions/classes in the __init__.py file of that package are directly visible, not sub-packages or modules

packages are just a special kind of module. Specifically, any module that contains a __path__ attribute is considered a package

Python files with a dash in the name, like my-file.py, cannot be imported with a simple import statement. Code-wise, import my-file is the same as import my - file which will raise an exception. Use importlib.import_module() instead

Pysically a package is a distribution unit, which provides one or more modules.

Modules in Python are simply Python files with the .py extension, which implement a set of functions.

Packages are namespaces which contain multiple packages and modules themselves

Each package in Python is a directory which MUST contain a special file called init.py.

To use the module bar from package foo, we can import it in two ways:

import foo.bar
# or
from foo import bar

In the first method, we must use the foo prefix whenever we access the module bar. In the second method, we don't, because we import the module to our module's namespace.

__init__.py:


__all__ = ["bar"]

__all__ = ['xyz','abc']

Python defines two types of packages, regular packages and namespace packages In Python 3.3+, namespace packages do not use init.py