Home > Mobile >  How to get Current working directory in the Google Compute Engine Python
How to get Current working directory in the Google Compute Engine Python

Time:10-16

Building an Web Application in the Google Compute Engine. Added the .json files in the /home/project directory and have python scripts in the /home/project/gsuite/pscript.py

How can i access the .json file that is present in the /home/project folder. I tried using os.getcwd() inside /home/project/gsuite/pscript.py file, but its returning as '/workspace'

Any help is appreciated!.

Thanks & Regards, Prashant

CodePudding user response:

You can jsut open the file like

path = "/home/project/data.json"
with open(path) as file:
   file.read()

if it won't work then you should try to change your working Dir

os.chdir(dir_path)

CodePudding user response:

After searching a lot, found some google documentation. We wont be able to read or write to files in the Google App Engine. For that we need use Google Storage to read and write to file. If the file is temporary we can use the /tmp directory.

Google Documentation that explains about this. https://cloud.google.com/appengine/docs/standard/python3/using-temp-files

  • Related