python培训之判断目录是否存在

发布时间:2022-11-10 09:50:46 人气:124 作者:多测师

  python的使用OS模块

  判断文件是是否存在

  os.path.isfile(path)

  判断目录是否存在

  os.path.isdir(path)

  判断文件是否存在

  # 使用 path 模块

  os.path.exists(path)

python培训之判断目录是否存在

  # 使用 access() 方法

  os.access(path, os.F_OK)

  使用 pathlib 模块

  import pathlib

  path = pathlib.Path('path/to/file')

  # 判断路径是否存在

  path.exists()

  # 判断是否为文件

  path.is_file()

  # 判断是否为目录

  path.is_dir()

  以上内容为大家介绍了python培训之判断目录是否存在,希望对大家有所帮助,如果想要了解更多Python相关知识,请关注多测师。https://www.e70w.com/xwzx/


返回列表
在线客服
联系方式

热线电话

17727591462

上班时间

周一到周五

二维码
线