Python 路径(七)

文件移植性

  1.动态获取当前文件的绝对路径  file_full_path = os.path.abspath(__file__)  __file__表示当前文件

  2.获取所给目录/文件所在目录  file_dir = os.path.dirname(file_full_path ) 继续往上获取到上级目录

  3.根据平台动态拼接路径 os.path.join(project_dir,"其他路径")

  4.分割

  5.判断是否目录/文件

  6.获取目录下所有

  os模块使用:https://www.runoob.com/python/os-file-methods.html

posted @ 2022-05-25 22:59  血染星辰  阅读(20)  评论(0)    收藏  举报