1 import os
 2 
 3 print '***获取当前目录***'
 4 print os.getcwd()
 5 print os.path.abspath(os.path.dirname(__file__))
 6 
 7 print '***获取上级目录***'
 8 print os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
 9 print os.path.abspath(os.path.dirname(os.getcwd()))
10 print os.path.abspath(os.path.join(os.getcwd(), ".."))
11 
12 print '***获取上上级目录***'
13 print os.path.abspath(os.path.join(os.getcwd(), "../.."))

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-04
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-28
  • 2022-12-23
  • 2021-11-07
相关资源
相似解决方案