在我的設置文件,我有以下行:如何獲取其他文件夾的父文件夾?
import os
import sys
PROJECT_ROOT = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(PROJECT_ROOT, "apps"))
file_path = os.path.join(os.path.realpath(os.path.dirname(__file__)),"..", "webapp.cfg")
在Windows環境下,如果os.path.realpath(os.path.dirname(__file__))
是file_path
D:\Projects\Test\src\test
我會有D:\Projects\Test\src\webapp.cfg
。這在Ubuntu 8.04下不起作用。
EDIT1:我在虛擬機上運行Ubuntu 8.04。我已經安裝了Python 2.5.2版本。
「不起作用」是什麼意思?你的電腦爆炸了嗎? `file_path`中有「粉色獨角獸」嗎?這個對我有用。 – SilentGhost 2011-02-02 15:07:15