__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