获取Python 脚本的所在目录
Tips: 一些工程开发中,使用相对路径,能提高工程的可移植性(如Python/shell的脚本工程)
- 获取Python脚本的所在目录的方法
You need to call os.path.realpath on file, so that when file is a filename without the path you still get the dir path:
import os
print os.path.dirname(os.path.realpath(__file__))