Python3判断文件是否存在不存在就创建

Python3判断文件是否存在不存在就创建
返回Python3,创建,文件,判断常用代码示例代码片段
  1. import os
  2. fname="/tmp/rumenz/123.txt"
  3. if not os.path.exists(fname):
  4. #调用系统命令行来创建文件
  5. os.system(r"touch {}".format(fname))
原文链接:https://rumenz.com/examples/Python3/python3-os-system-touch.html

【Linux常用命令速查手册】关注【入门小站】,后台回复 「1001」 自取。

点击下面标题即可获取对应PDF资料
↑回到顶部↑
入门小站 @2018