% run 命令

先在目录下写.py的文件

def f(x, y, z):
    return (x + y) / z

a = 5
b = 6 
c = 7.5

result = f(a, b, c)

jupyter notebook 输入%load ipython_script_test.py:将脚本导入一个代码单元

# %load ipython_script_test.py
#!/usr/bin/env python

# In[8]:


def f(x, y, z):
    return (x + y) / z

a = 5
b = 6 
c = 7.5

result = f(a, b, c)


jupyter notebook 输入%run ipython_script_test.py:运行Python程序文件

%run ipython_script_test.py

输入c

c
7.5

输入result

result
1.4666666666666666

你可能感兴趣的:(% run 命令)