Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在另一个文件的类中调用函数?_Python_Python 3.x - Fatal编程技术网

Python 如何在另一个文件的类中调用函数?

Python 如何在另一个文件的类中调用函数?,python,python-3.x,Python,Python 3.x,我在data.py中有以下代码 import numpy as np from scipy import stats class Data: def __init__(self, x, y): """ (Data, list, list) -> NoneType Create a new data object with two attributes: x and y. """ self.x = x

我在data.py中有以下代码

import numpy as np

from scipy import stats

class Data:

    def __init__(self, x, y):
        """ (Data, list, list) -> NoneType

        Create a new data object with two attributes: x and y.
        """
        self.x = x
        self.y = y



    def compute_least_squares_fit(self):
        """ (Data) -> number, number

        Return the intercept and slope of the simple linear regression fit
        of the data.
        """

        slope, intercept, r_value, p_value, std_err = stats.linregress(self.x,self.y)
        return slope, intercept

    def compute_SST(self):
        """ (Data) -> number

        Return the sum of squares total (SST).
        """

        avg_y = np.mean(self.y)
        squared_errors = (self.y - avg_y) ** 2
        return np.sum(squared_errors)
我在另一个文件里有这个代码

import numpy as np

from scipy import stats

import matplotlib.pyplot as plt

from data import Data


class SLR:

    def __init__(self, data):
        """ (SLR, Data) -> NoneType

        Create a new simple linear regression object from data,
        with data data, intercept beta0, and slope beta1.



        """

如何使用从另一个文件到这个文件的截距和斜率?

\uuuu init\uuuu
方法中,您有一个参数
data
,它应该是
data
的一个实例。现在调用
data.compute\u least\u squares\u fit()
并使用返回值。谢谢,但是如何返回值呢?我可以直接使用截距和斜率变量吗?在
方法中,您有一个参数
data
,它应该是
data
的一个实例。现在调用
data.compute\u least\u squares\u fit()
并使用返回值。谢谢,但是如何返回值呢?我可以直接使用截距和斜率变量吗?