python怎么获取当前文件路径-所在位置

132 阅读1分钟
#!/bin/env python
#-*- encoding=utf8 -*-

import os,sys

# 获取当前文件的所在目录
print("os.path.realpath(__file__)=%s" % os.path.realpath(__file__))

# 获取当前文件的所在目录
print("os.path.dirname(os.path.realpath(__file__))=%s" % os.path.dirname(os.path.realpath(__file__)))

# 获取当前文件的所在目录
print("os.path.split(os.path.realpath(__file__))=%s" % os.path.split(os.path.realpath(__file__))[0])