Hi there,
with the python code below I am able to read the file name of the current Google Colab notebook automatically. I now would like to read the whole path of the notebook including (or excluding) the file name. Anyone can help?
Thanks in advance!!
In:
from requests import get
from socket import gethostname, gethostbyname
ip = gethostbyname(gethostname()) # 172.28.0.12
filename = get(f"http://{ip}:9000/api/sessions").json()[0]["name"]
print(filename)
Out:
NotebookTest.ipynb
The desired result should be the whole path like
"My Drive/Colab Notebooks/NotebookTest.ipynb"
The output of "My Drive/Colab Notebooks"
would also be okay.
I tried out changing "name" to "path" in the get-command, but the result gives me something unusable.
Solution at Get the path of the notebook on Google Colab doesn't work for me, as I wish to adapt it to the code indicated above.