python 获取绝对路径的五种方式

print(os.path.abspath(__file__))
# /Users/s/PycharmProjects/dr_check/main.py

print(sys.path[0])
# /Users/s/PycharmProjects/dr_check

print(os.getcwd())
# /Users/s/PycharmProjects/dr_check

print(os.path.realpath(__file__))
# /Users/s/PycharmProjects/dr_check/main.py

print(os.path.split(os.path.realpath(__file__)))
# ('/Users/s/PycharmProjects/dr_check', 'main.py')

你可能感兴趣的:(学习笔记,python,开发语言,pycharm)