使用Colab Notebook在我们的Google驱动器中获取文件的共享链接 [英] Get a shareable link of a file in our google drive using Colab notebook
本文介绍了使用Colab Notebook在我们的Google驱动器中获取文件的共享链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以告诉我如何使用Colab笔记本自动获取Google驱动器中文件的共享链接吗?
could anyone please inform me how to automatically get a shareable link of a file in our google drive using Colab notebook?
谢谢.
推荐答案
您可以使用xattr
获取file_id
You can use xattr
to get file_id
from subprocess import getoutput
from IPython.display import HTML
from google.colab import drive
drive.mount('/content/drive') # access drive
# need to install xattr
!apt-get install xattr > /dev/null
# get the id
fid = getoutput("xattr -p 'user.drive.id' '/content/drive/My Drive/Colab Notebooks/R.ipynb' ")
# make a link and display it
HTML(f"<a href=https://colab.research.google.com/drive/{fid} target=_blank>notebook</a>")
在这里,我在/Colab Notebooks/R.ipynb
处访问我的笔记本文件,并创建一个链接以在Colab中打开它.
Here I access my notebook file at /Colab Notebooks/R.ipynb
and make a link to open it in Colab.
这篇关于使用Colab Notebook在我们的Google驱动器中获取文件的共享链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文