日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python importlib_importlib --- import 的实现 — Python 3.10.0a2 文档

發布時間:2023/12/1 python 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python importlib_importlib --- import 的实现 — Python 3.10.0a2 文档 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

3.7 新版功能.

這個模塊使得Python的導入系統提供了訪問*包*內的*資源*的功能。如果能夠導入一個包,那么就能夠訪問那個包里面的資源。資源可以以二進制或文本模式方式被打開或讀取。

資源非常類似于目錄內部的文件,要牢記的是這僅僅是一個比喻。資源和包不是與文件系統上的物理文件和目錄一樣存在著。

注解

This module provides functionality similar to pkg_resources Basic

Resource Access

without the performance overhead of that package. This makes reading

resources included in packages easier, with more stable and consistent

semantics.

加載器想要支持資源讀取應該實現一個由 importlib.abc.ResourceReader 指定的``get_resource_reader(fullname)`` 方法。

The following types are defined.

importlib.resources.Package?

The Package type is defined as Union[str, ModuleType]. This means

that where the function describes accepting a Package, you can pass in

either a string or a module. Module objects must have a resolvable

__spec__.submodule_search_locations that is not None.

importlib.resources.Resource?

This type describes the resource names passed into the various functions

in this package. This is defined as Union[str, os.PathLike].

The following functions are available.

importlib.resources.files(package)?

Returns an importlib.resources.abc.Traversable object

representing the resource container for the package (think directory)

and its resources (think files). A Traversable may contain other

containers (think subdirectories).

package is either a name or a module object which conforms to the

Package requirements.

3.9 新版功能.

importlib.resources.open_binary(package, resource)?

Open for binary reading the resource within package.

package is either a name or a module object which conforms to the

Package requirements. resource is the name of the resource to open

within package; it may not contain path separators and it may not have

sub-resources (i.e. it cannot be a directory). This function returns a

typing.BinaryIO instance, a binary I/O stream open for reading.

importlib.resources.open_text(package, resource, encoding='utf-8', errors='strict')?

Open for text reading the resource within package. By default, the

resource is opened for reading as UTF-8.

package is either a name or a module object which conforms to the

Package requirements. resource is the name of the resource to open

within package; it may not contain path separators and it may not have

sub-resources (i.e. it cannot be a directory). encoding and errors

have the same meaning as with built-in open().

This function returns a typing.TextIO instance, a text I/O stream open

for reading.

importlib.resources.read_binary(package, resource)?

Read and return the contents of the resource within package as

bytes.

package is either a name or a module object which conforms to the

Package requirements. resource is the name of the resource to open

within package; it may not contain path separators and it may not have

sub-resources (i.e. it cannot be a directory). This function returns the

contents of the resource as bytes.

importlib.resources.read_text(package, resource, encoding='utf-8', errors='strict')?

Read and return the contents of resource within package as a str.

By default, the contents are read as strict UTF-8.

package is either a name or a module object which conforms to the

Package requirements. resource is the name of the resource to open

within package; it may not contain path separators and it may not have

sub-resources (i.e. it cannot be a directory). encoding and errors

have the same meaning as with built-in open(). This function

returns the contents of the resource as str.

importlib.resources.path(package, resource)?

Return the path to the resource as an actual file system path. This

function returns a context manager for use in a with statement.

The context manager provides a pathlib.Path object.

Exiting the context manager cleans up any temporary file created when the

resource needs to be extracted from e.g. a zip file.

package is either a name or a module object which conforms to the

Package requirements. resource is the name of the resource to open

within package; it may not contain path separators and it may not have

sub-resources (i.e. it cannot be a directory).

importlib.resources.is_resource(package, name)?

Return True if there is a resource named name in the package,

otherwise False. Remember that directories are not resources!

package is either a name or a module object which conforms to the

Package requirements.

importlib.resources.contents(package)?

Return an iterable over the named items within the package. The iterable

returns str resources (e.g. files) and non-resources

(e.g. directories). The iterable does not recurse into subdirectories.

package is either a name or a module object which conforms to the

Package requirements.

總結

以上是生活随笔為你收集整理的python importlib_importlib --- import 的实现 — Python 3.10.0a2 文档的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。