python中的库和模块有什么区别_Python中的模块和库之间有什么区别?

The Python Tutorial – Modules

>模块:

A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended.

>包装:

Packages are a way of structuring Python’s module namespace by using “dotted module names”.

如果您阅读import语句的文档,将提供更多详细信息,例如:

Python has only one type of module object, and all modules are of this

type, regardless of whether the module is implemented in Python, C, or

something else. To help organize modules and provide a naming

hierarchy, Python has a concept of packages.

You can think of packages as the directories on a file system and

modules as files within directories, but don’t take this analogy too

literally since packages and modules need not originate from the file

system. For the purposes of this documentation, we’ll use this

convenient analogy of directories and files. Like file system

directories, packages are organized hierarchically, and packages may

themselves contain subpackages, as well as regular modules.

It’s important to keep in mind that all packages are modules, but not

all modules are packages. Or put another way, packages are just a

special kind of module. Specifically, any module that contains a

__path__ attribute is considered a package.

因此,术语模块是指一个特定的实体:它是一个类,其实例是在python程序中使用的模块对象.类似地,它也被用来引用这些实例“被创建”的文件系统中的文件.

术语脚本用于指代要执行其目标的模块.它与“程序”或“应用程序”具有相同的含义,但通常用于描述简单和小程序(即,最多有几百行的单个文件).写一个脚本需要几分钟或几个小时.

术语库仅仅是一系列代码的通用术语,旨在为许多应用程序使用而设计.它提供了特定应用程序可以使用的一些通用功能.

当模块/包/其他东西被“发布”时,人们通常将其称为图书馆.通常,库包含一个包或多个相关包,但它甚至可以是单个模块.

库通常不提供任何特定功能,即您不能“运行库”.

根据上下文,API可以具有不同的含义.例如:

>它可以定义一个协议,如DB API或buffer protocol.

>它可以定义如何与应用程序交互(例如Python/C API)

>当与库/包相关时,它只是该库为其功能提供的接口(功能/类/常量等)

在任何情况下,API不是python代码.这可能是或多或少正式的描述.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值