作者:elfin  资料来源:原创


1、判断目录是否存在并创建

if not os.path.exists(PROJECT_DIR + save_json):
    os.makedirs(PROJECT_DIR + save_json)

os.path.exists()用于判断路径是否存在;os.makedirs()可用于创建多层目录结构。

os.mkdir(path)

os.mkdir(path)只能创建一个文件夹,路径除最后一个文件夹不存在外,如果还有文件夹不存在,会报错!

相关文章:

  • 2022-12-23
  • 2021-06-03
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
猜你喜欢
  • 2021-09-17
  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案