程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Relationship among Python libraries, packages and modules

編輯:Python

python library 、 Relationship between package and module

1、 modular

Module is a kind of .py It's a suffix python file , It can be understood as a well written python file , To use as a library file , Must include function ; Module name is this .py The name of the document . The name of the module as a global variable __name__ The value of , It can be acquired or imported by other modules .

The module is imported through import To achieve , The way to import the module is as follows :import Specific module name

python The module is :
Self contained and organized code snippets are modules .
In the form of : Save the written code as a file . This file is a module .sample.py Where file name smaple Name the module .

#python View all installed modules in the environment 
>>>help("modules")

2、 package

Is a concept based on modules , Package the files for easy management . The first file in the package directory is init.py, Then there are some module files and subdirectories , Suppose there is one in the subdirectory init.py, So it's the sub package of this bag . A good application scenario for package files is :

A The developer wrote an implementation x Functional modules , Name it perfect;

B Kaifa has written an implementation y Functional modules , Name it perfect;

C Users want to use y Functional modules , But because of the same name , The program cannot distinguish between two files . To solve the problem , Two files with the same name can be placed in packages with different package names , The specific module is determined by the combination of package name and file name .

The reference mode of specific modules in the package is :import Package name . Module name

python Bag is :
Package is a hierarchical file directory structure , It defines by n A module or n Composed of sub packages python Application execution environment .

More popular : A package is a package that contains __init__.py File directory , There must be this in this directory __init__.py Files and other modules or sub packages .

3、 library

Python The library in borrows the concept of other programming languages , There is no specific definition ,Python The library emphasizes its functionality . stay Python in , Modules and packages with certain functions can be called Libraries . The module consists of many functions , The package consists of many modular structures , Libraries can also contain packages 、 Modules and functions .

therefore :python What is really used in is packages and modules , Library is a general term in an abstract sense .

python Kuo is :

Refer to other programming languages , Is refers to python The code set that completes certain functions in , Code combinations for users . stay python Is in the form of packages and modules .

library : With relevant functional modules ( package ) Set . This is also Python One of the major features of , That is, it has a strong standard library 、 Third party libraries and custom modules .

# View all installed third-party libraries and version numbers 
(odc) [[email protected] testpy]# pip list
# View the details of a library 
(odc) [[email protected] testpy]# pip show odc-stac
# View the help documentation for all third-party libraries 
(base) [[email protected] ~]# python -m pydoc -p 0
Server ready at http://localhost:45998/
Server commands: [b]rowser, [q]uit

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved