【发布时间】:2011-06-20 01:01:27
【问题描述】:
在我的设置文件中,我有以下几行:
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中得到“粉色独角兽”吗?它对我有用。 -
python的版本不一样吗? 8.04 是相当旧的 Ubuntu 版本,因此默认的 python 安装将是相同的年龄。
-
它说没有这样的文件或目录:'/home/Projects/Test/src/test/../webapp.cfg
-
@Seitaridis:嗯,有这样的文件吗?
-
您可能需要考虑添加
file_path = os.path.normpath(file_path)以消除上层引用 (/../)。不过,我怀疑这会解决您的问题。因此,评论而不是答案。 :)
标签: python windows django linux path