__DIR__ 文件所在的目录。如果用在被包括文件中,则返回被包括的文件所在的目录。它
等价于 dirname(__FILE__)。除非是根目录,否则目录中名不包括末尾的斜杠。
该魔术常量在include文件时候非常有用。那么python中该如何做到?
在http://stackoverflow.com/questions/6416321/python-equivalent-of-phps-dir-magic-constant中提到了相应的解决方法。
import os.path
_dir = os.path.dirname(os.path.abspath(__file__))
import demo.test
print _dir