Skip to main content

获取临时 pathlib.Path 的快速方法。

项目描述

临时路径

pathlib.Path提供一种在系统定义的临时空间中 获取文件的快捷方式。temppath不wrap ,因为tempfile.NamedTemporaryFile在关闭时自动删除,并且不允许在 Windows中写入、关闭然后读取相同的文件,这与 Unix 实现不一致。由于temppath 提供了pathlib.Path对象,因此这不是问题。

用法

有一个不错的上下文管理器,它将为您删除路径。

from temppath import TemporaryPathContext

with TemporaryPathContext() as t:
    t.write_text('the quick brown fox jumps over the lazy dog')
    ...
    do_something_awesome_that_reads(t)

# The file is removed when you leave the `with` context.

如果您需要更多控制权,您还可以选择自己清理它。

from temppath import TemporaryPath

t = TemporaryPath()
t.write_text('the quick brown fox jumps over the lazy dog')
...
do_something_awesome_that_reads(t)
...
t.unlink()

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

temppath-2021.236.907.tar.gz (3.0 kB 查看哈希

已上传 source

内置分布

temppath-2021.236.907-py3-none-any.whl (3.2 kB 查看哈希

已上传 py3