1

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.

D.L
  • 4,339
  • 5
  • 22
  • 45
Rapsta
  • 23
  • 4
  • i like this question as i had been trying to do similar. I think that colab files need google permissions for security purposes. – D.L Jun 09 '23 at 16:13
  • Then I hope we get a solution on this, please upvote question. Thanks. – Rapsta Jun 09 '23 at 16:23

0 Answers0