我們正在使用部署到 Windows 和 Linux 的代碼存儲庫 - 有時位於不同的目錄中。項目中的模塊之一應該如何引用項目中的非 Python 資源之一(CSV 文件等)?
如果我們這樣做:
thefile=open("test.csv")
or:
thefile=open("../somedirectory/test.csv")
僅當腳本從一個特定目錄或目錄的子集運行時才會起作用。
我想做的是:
path=getBasePathOfProject()+"/somedirectory/test.csv" thefile=open(path)
有可能嗎?