The difference between object-oriented module, library, and package for Python entry

background

There are some basic nouns in Python, and many people, especially some beginners, may feel dizzy when they hear them.

Here, briefly summarize the general differences between module, library, and package.

 

Introduction to modules in Python

module, Chinese translation is: module

The module in Python, to put it bluntly, is the Python file, and the python file is generally suffixed with py, so it is just your xxx.py.

 

Introduction to library

library, Chinese translation is: library, also often called: library file

The reason why the library in Python is not mentioned here is because the word library itself is generally used for other compiled languages, such as C, C# and other languages.

The library in common C/C# and other languages ​​generally refers to:

Static library file: xxx.a

Dynamic library file: xxx.dll

 

Introduction to Packages in Python

package, Chinese translation is: package

A package in Python can be simply understood as a combination of a group of modules and a bunch of (related) modules;

 

Difference between module and library in Python

For library and module, to put it bluntly, they both provide certain functions for others to call.

From this aspect, it can also be understood as:

In Python, library is equivalent to module;

However, in Python, library is rarely said, and normally, module is said;

So, in short:

  • Most libraries refer to libraries and library files in languages ​​such as C and C#;
  • In Python, the word library is rarely used;
  • The name of "library" and "library file" in Python is called module, module;
  • Whether you are a beginner or a master of Python, my personal suggestion is to continue to use the official, common name, use the word module instead of the word library;

 

Difference between module and package in Python

Import a single module, generally like this

import my_module

Importing a package generally looks like this:

from my_package.timing.danger.internets import function_of_love

It can be simply understood as:

  • module: a single module, usually a single (occasionally multiple) python file;
  • package: A combination of multiple related modules. It must be a combination of multiple, related, Python files; package is used to organize related modules together as a whole;

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324604848&siteId=291194637