<p>下面的代码非常适合我。
一。将所有ipynb文件复制到colab中的一个文件夹中
2。从colab共享ipynb文件,请参见链接:
<a href="https://www.pingshiuanchua.com/blog/post/importing-your-own-python-module-or-python-file-in-colaboratory" rel="nofollow noreferrer">https://www.pingshiuanchua.com/blog/post/importing-your-own-python-module-or-python-file-in-colaboratory</a>
三。然后执行以下步骤:</p>
<pre><code>!pip install import-ipynb
import import_ipynb
# Install the PyDrive wrapper & import libraries.
# This only needs to be done once per notebook.
!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
# Authenticate and create the PyDrive client.
# This only needs to be done once per notebook.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
# Copy the link and remove the front part of the link (i.e. https://drive.google.com/open?id=) to get the file ID.
your_module = drive.CreateFile({'id':'eyetgd1zyxwvutsrqponmlkjihgfedcba'})
your_module.GetContentFile('myfile.ipynb')
import myfile
</code></pre>