使用“临时文件” python 中的文件夹

发布于 2024-08-29 10:16:05 字数 192 浏览 2 评论 0原文

我最近编写了一个查询 PyPI 并下载包的脚本;但是,该包会下载到用户定义的文件夹中。

我想修改脚本,以便我下载的文件进入临时文件夹(如果未指定文件夹)。

*nix 机器中的临时文件文件夹是“/tmp”;我可以使用任何Python方法来查找特定机器中的临时文件文件夹吗?

如果没有,有人可以提出解决这个问题的替代方案吗?

I recently wrote a script which queries PyPI and downloads a package; however, the package gets downloaded to a user defined folder.

I`d like to modify the script in such a way that my downloaded files go into a temporary folder, if the folder is not specified.

The temporary-files folder in *nix machines is "/tmp" ; would there be any Python method I could use to find out the temporary-files folder in a particular machine?

If not, could someone suggest an alternative to this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

耳根太软 2024-09-05 10:16:05

Python 有一个用于使用临时文件和文件夹的内置模块。您可能需要 tempfile.mkdtemp()

Python has a built-in module for using temporary files and folders. You probably want tempfile.mkdtemp().

醉城メ夜风 2024-09-05 10:16:05

也许是 tempfile 模块?

Perhaps the tempfile module?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文