lakers009 发表于 2018-8-14 08:08:54

python3获取文件目录和文件

import os,sys  

  
if __name__=="__main__":
  print("__file__ = %s" % __file__)
  #获取文件相对路径
  print("sys.argv) = %s" % sys.argv)
  #获取文件的全路径加文件名
  print("sys.path = %s " % sys.path)
  #获取文件的全路径
  print("os.getcwd() = %s" % os.getcwd())
  #获取当前目录路径(和linux的pwd一样)
  print("os.path.realpath(__file__) = %s " % os.path.realpath(__file__))
  #获取文件的全路径加文件名
  print("os.path.abspath(__file__) = %s " % os.path.abspath(__file__))
  #获取文件的绝对路径加文件名
  print("os.path.dirname(os.path.realpath(__file__)) = %s " % os.path.dirname(os.path.realpath(__file__)))
  #获取文件路径
  print("os.path.basename(os.path.realpath(__file__)) = %s " % os.path.basename(os.path.realpath(__file__)))
  #获取文件名
  print("os.path.split(os.path.realpath(__file__)) = %s " % os.path.split(os.path.realpath(__file__)))
  #获取文件路径
  print("os.path.split(os.path.realpath(__file__)) = %s " % os.path.split(os.path.realpath(__file__)))
  #获取文件名
页: [1]
查看完整版本: python3获取文件目录和文件