Python 3.x 从进度条(Python3)导入类中的函数获取值

Python 3.x 从进度条(Python3)导入类中的函数获取值,python-3.x,oop,Python 3.x,Oop,这应该是一个简单的问题,但我不知道如何有效地用谷歌搜索它 我有Main.py,它从GetPointDistance.py文件导入类GetPointDistance py可以将变量发送到GetPointDistance,但是我如何设置它以使变量(在main中调用)得到更新,我真的想将其用于progressbar,但让我们先来看看,我想返回GetPointDistance中for循环上的x值,并在main中使用print函数 例如: (Main.py) (getPointDistance.py) 我

这应该是一个简单的问题,但我不知道如何有效地用谷歌搜索它

我有Main.py,它从GetPointDistance.py文件导入类GetPointDistance

py可以将变量发送到GetPointDistance,但是我如何设置它以使变量(在main中调用)得到更新,我真的想将其用于progressbar,但让我们先来看看,我想返回GetPointDistance中for循环上的x值,并在main中使用print函数

例如:

(Main.py)

(getPointDistance.py)


我想从getPointDistance(I)中返回一个值,并在Main中访问它

,因为你把事情搞混了
calculate_nearest_top
是实例方法,您需要一个实例来调用它,就像
gpd=GetPointDistance();gpd.计算最接近的顶部()。如果要向其传递值,则需要声明为
def calculate\u nearest\u top(self,argument)
。似乎你不需要一个类来计算最近的距离,因为你在方法体中不使用self,一个简单的函数就足够了。在这种情况下,你可以去掉
GetPointDistance
类,直接在
near\dist\u top
value=GetPointDistance.calculate\u top()中调用它;print(value)
I过于简化/糟糕的示例,我将添加一些真实的代码。你把事情搞混了
calculate_nearest_top
是实例方法,您需要一个实例来调用它,就像
gpd=GetPointDistance();gpd.计算最接近的顶部()。如果要向其传递值,则需要声明为
def calculate\u nearest\u top(self,argument)
。似乎你不需要一个类来计算最近的距离,因为你在方法体中不使用self,一个简单的函数就足够了。在这种情况下,你可以去掉
GetPointDistance
类,直接在
near\dist\u top
value=GetPointDistance.calculate\u top()中调用它;print(value)
I过于简化/糟糕的示例,我将添加一些真正的代码。
import getPointDistance

class MyWindow(QtWidgets.QMainWindow):
def __init__(self):
    super(MyWindow, self).__init__()
    uic.loadUi('pyqtdesigner.ui', self)
    ...
    ...
    def near_dist_top(self):
        getPointDistance.GetPointDistance.calculate_nearest_top(self, distance)
        print(value_from_getPointDistance)
class GetPointDistance:
    def calculate_nearest_top(self):
        top_dist_list = []
        for i in range(len(T)):
            print(i)
            return i