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