在Jupyter notebook中快速写入和运行py文件

1 写入py文件

%%file hello.py
def func_inside_script(x, y):
    return x + y*x
print('Hello World')

在这里插入图片描述

2 运行py文件

%run hello.py

在这里插入图片描述

无法嵌套运行

%%file hello2.py
%run hello.py
#def func_inside_script(x, y):
#    return x + y*x
print('Hello World 2')

Writing hello2.py

%run hello2.py

SyntaxError: invalid syntax
在这里插入图片描述

ref: https://mp.weixin.qq.com/s/9-eIRKgk8xxp4gZmu-Fqaw


版权声明:本文为weixin_45288557原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。