import os


def load_file():
    # 获取当前文件路径
    current_path = os.path.abspath(__file__)
    # 获取当前文件的父目录
    father_path = os.path.abspath(os.path.dirname(current_path) + os.path.sep + ".")
    # config.ini文件路径,获取当前目录的父目录的父目录与congig.ini拼接
    config_file_path = os.path.join(os.path.abspath(os.path.dirname(current_path) + os.path.sep + ".."), 'config.ini')
    print('当前目录:' + current_path)
    print('当前父目录:' + father_path)
    print('config.ini路径:' + config_file_path)


load_file()

import os

path1=os.path.abspath(’.’) # 表示当前所处的文件夹的绝对路径
print(path1)
path2=os.path.abspath(’…’) # 表示当前所处的文件夹上一级文件夹的绝对路径
print(path2)

 

相关文章:

  • 2022-12-23
  • 2021-09-25
  • 2021-08-29
  • 2022-02-11
  • 2021-05-19
  • 2021-11-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2022-02-15
  • 2021-06-18
相关资源
相似解决方案