在Google Colab中导入.py文件 [英] Importing .py files in Google Colab
本文介绍了在Google Colab中导入.py文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在.py文件中上传我的代码并将它们导入到colab代码单元格中?
Is there any way to upload my code in .py files and import them in colab code cells?
我找到的另一种方法是创建一个本地Jupyter笔记本,然后将其上传到Colab,这是唯一的方法吗?
The other way I found is to create a local Jupyter notebook then upload it to Colab, is it the only way?
推荐答案
您可以先保存,然后将其导入。
You can save it first, then import it.
from google.colab import files
src = list(files.upload().values())[0]
open('mylib.py','wb').write(src)
import mylib
这篇关于在Google Colab中导入.py文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文