【问题标题】:How to store file in Windows OS instead of `/tmp` unix?如何将文件存储在 Windows 操作系统而不是 `/tmp` unix 中?
【发布时间】:2019-04-17 15:57:45
【问题描述】:

以下代码在unix-base系统上运行良好,使用/tmp存储文件,但是在windows操作系统下如何使用呢?

    local_filename, headers = urllib.request.urlretrieve('http://127.0.0.1/translations/python-3.7.3.exe')
    print(local_filename)
    fd = open(local_filename)
    fd.close()

【问题讨论】:

  • 你可以提供一个filenamearguemt
  • 你试过了吗?

标签: python windows file urllib


【解决方案1】:

来自文档:

将 URL 检索到磁盘上的临时位置。

如果您不提供filename 参数,那么urlretrieve() 将调用tempfile.NamedTemporaryFile() 在您操作系统上的临时文件的任何位置创建一个文件。这也适用于 Windows(文件将在 %TEMP% 下创建)。

如果您需要特定位置,请传递 filename 参数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-02
    • 1970-01-01
    • 2020-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-17
    • 2013-03-04
    相关资源
    最近更新 更多