【问题标题】:Make sure a directory exists确保目录存在
【发布时间】:2023-02-12 01:25:51
【问题描述】:

Deno 的 ensureDir 对应的 Python 是什么?

使用示例:

import { ensureDir, ensureDirSync } from "https://deno.land/std/fs/mod.ts";
ensureDir("./logs").then(
  () => console.log("Success Created"),
).catch((err) => console.log(err));

【问题讨论】:

    标签: python file-handling


    【解决方案1】:

    您可以使用pathlib.Path.mkdir。例子:

    pathlib.Path(f"{pathlib.Path.home()}", ".local", "extra", "path").mkdir(
        parents=True, exist_ok=True
    )
    

    【讨论】:

      猜你喜欢
      • 2014-10-15
      • 1970-01-01
      • 2020-02-21
      • 1970-01-01
      • 1970-01-01
      • 2015-09-02
      • 2021-03-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多