当前位置: 首页 > 图灵资讯 > 行业资讯> python的假如路径不存在如何写

python的假如路径不存在如何写

发布时间:2025-02-20 20:42:09

如果路径不存在,写python的方法:

用if句判断“用if句判断”os.path.exists()返回值是否为false,如果是false,则该路径不存在

示例代码如下:

importos
ifos.path.exists("kk\\kk.txt")==False:
#os.makedirs()
print("路径不存在")

执行结果如下:

微信截图_20200608102533.jpg

更多Python知识,请关注:Python自学网!!

相关文章

python3兼容python2吗

python3兼容python2吗

2025-05-09
python3 whl怎么安装

python3 whl怎么安装

2025-05-09
python 字典怎么提取value

python 字典怎么提取value

2025-05-09
python 怎样计算字符串的长度

python 怎样计算字符串的长度

2025-05-09
python 怎么样反向输出字符串

python 怎么样反向输出字符串

2025-05-09
python 怎么判断字符串开头

python 怎么判断字符串开头

2025-05-09