1.模块建立实例
#《oil_calculate.py》
class oil_calculate():
def __init__(self):
self.Lpp = 185
self.depth = 18
self.draft = 12.8
......
def time_calculate(self,a0,a1):
......
def oil_WBMs(self,df_AIS,x):
b=self.time_calculate(......)
......
df_BBM_speed=......
2.代码说明
调用函数中赋的值(df_BBM_speed)
df_BBM_speed在《oil_calculate.py》中并不是一个函数,而是调用函数后得到的值,此时如果需要在main中调用df_BBM_speed,可用:
from oil_calculate import oil_calculate
df_BBM_speed = add_train_data().df_BBM_speed
比如需要调用处理好的训练集,就会用到这个
模块中函数互相调用
(1)方法一:
格式:类名.方法名(self)
(2)方法二:
格式:self.方法名(方法列表)
方法列表不应该包括self
同文件夹调用错误
如果运行以下代码发现错误:
from oil_calculate import oil_calculate
可以改成:
from 文件名.oil_calculate import oil_calculate