在 Google Compute Engine 中構建 Web 應用程式。在/home/project目錄中添加了 .json 檔案,并在/home/project/gsuite/pscript.py 中有 python 腳本
我如何訪問 /home/project 檔案夾中存在的 .json 檔案。我嘗試在/home/project/gsuite/pscript.py檔案中使用os.getcwd(),但它回傳為“/workspace”
任何幫助表示贊賞!
感謝和問候, Prashant
uj5u.com熱心網友回復:
你可以像這樣打開檔案
path = "/home/project/data.json"
with open(path) as file:
file.read()
如果它不起作用那么你應該嘗試改變你的作業目錄
os.chdir(dir_path)
uj5u.com熱心網友回復:
經過大量搜索,找到了一些谷歌檔案。我們將無法讀取或寫入 Google App Engine 中的檔案。為此,我們需要使用 Google Storage 來讀取和寫入檔案。如果檔案是臨時檔案,我們可以使用該/tmp目錄。
對此進行解釋的 Google 檔案。https://cloud.google.com/appengine/docs/standard/python3/using-temp-files
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/316758.html
