我在 Google Colab 上有一个 ipynb my_functions.ipynb,它由一个简单的函数组成。
def get_mean(dat, col_nm):
return dat[col_nm].mean()
Run Code Online (Sandbox Code Playgroud)
我想从 Google Colab 上的另一个 python 笔记本中other_notebook.ipynb获取这个函数,以便我可以使用它,但是我在任何地方都找不到解决方案。
感谢对此的任何帮助。
谢谢,
加雷思
当我在 Colaboratory 中运行Python 脚本时,它正在运行所有以前的代码单元。
有什么方法可以保存以前的单元格状态/输出,我可以在返回笔记本后直接运行下一个单元格。
我想简化代码.所以我做了一个utils.py,但Google Colaboratory目录是"/ content"我读了其他问题.但这不是我的解决方案
在Google的Colab笔记本中,如何从Python文件中调用函数?
%%writefile example.py
def f():
print 'This is a function defined in a Python source file.'
# Bring the file into the local Python environment.
execfile('example.py')
f()
This is a function defined in a Python source file.
Run Code Online (Sandbox Code Playgroud)
看起来好像只使用def().
使用这个,我总是在单元格中编写代码.
但我想要这个代码
import example.py
example.f()
Run Code Online (Sandbox Code Playgroud)