做课题和数据挖掘竞赛用python比较多,比较常用的是在服务器终端输入jupyter notebook --ip 0.0.0.0,打开jupyter notebook的一个后台,并在本地windows电脑浏览器进入该服务端写python代码。
将.ipynb和.py结合,可以使得jupyter notebook的工程文件目录更有条理,一些函数可以定义在.py文件中,需要调用这些文件时,就导入到.ipybn中执行。
那在jupyter notebook中调用同,怎么在.ipynb.py中调用.py文件呢?
举个栗子:
在同一个目录下,有call_hello.ipynb和hello.py两个文件:
hello.py中定义了hello函数如下:
def hello():
print('say hello');
在call_hello.ipynb中调用hello()函数:
from hello import *
hello()
输出: say hello
但是修改.py文件中的代码后,必须在ipynb中reload模块,才会生效。
如果hello.py中的代码修改成:
def hello():
print('say hello,bye');
在call_hello.ipynb中再次调用hello()函数,依然输出:say hello
重新导入hello模块:
from imp import reload
reload(hello)
hello()
这时候会输出:say hello, bye
bingo!