将类赋值给对象的问题


import sys
from PyQt5.QtWidgets import *
from PyQt5.QAxContainer import *
from PyQt5.QtCore import *
import time
sys.stdout = open('A_cook_list.txt', 'a')
TR_REQ_TIME_INTERVAL = 1
class Systembox(QAxWidget):
def __init__(self):
super().__init__()
self._create_sysembox_instance()
self._set_signal_slots()
self.c = 0
self.result = []
def _create_systembox_instance(self):
skip...
def _set_signal_slots(self):
skip...
def comm_connect(self):
skip...
def _event_connect(self, err_code):
skip...
def set_input_value(self, id, value):
skip...
def comm_rq_data(self, skip...
skip...
def _comm_get_data(self, skip...
skip...
def _get_repeat_cnt(self, skip...
skip...
def _receive_tr_data(self, skip...
skip...
def _AWS10000(self, rqname, trcode):
cnn = self._get_repeat_cnt(trcode, rqname)
for i in range(cnn):
date = self._comm_get_data(trcode, rqname, i, "DATA")
self.c = self.c + 1
if self.c > 299:
systembox.remained_data = False
self.c = self.c - 300
if len(self.result) < 300:
self.result.append(date)
if len(self.result) >= 300:
self.print_result(self.result)
self.result = []
def print_result(self, result):
print(result)
if __name__ == "__main__":
app = QApplication(sys.argv)
systembox = Systembox()
Systembox.comm_connect()
while True:
skip...
while systembox.remained_data == True:
skip...
sys.stdout.close()

以上代码运行良好。但是,我想以不同的方式输出上述代码的最终值。因此,我将代码修改如下


skip...
def print_result(self, result):
return result
aaa = Systembox()
aaa.print_result(result)
print(aaa.result)
if __name__ == "__main__":
skip...

但是没有输出。

我想控制systemmebox类之外的输出。因为,我正试图将输出放入pandas DataFrame中。我认为pandas DataFrame应该写在另一个模块中。

重要的是,我想把这段代码输出到systemmebox类的外部。

长久以来,我一直在试图解决这个问题。请多多帮忙。

因为您的print_result()所做的是返回result值(然后将被打印)。我认为最好删除它并修复您的代码位

class Systembox(QAxWidget):
# some code
def _AWS10000(self, rqname, trcode):
cnn = self._get_repeat_cnt(trcode, rqname)
for i in range(cnn):
date = self._comm_get_data(trcode, rqname, i, "DATA")
self.c = self.c + 1
if self.c > 299:
systembox.remained_data = False
self.c = self.c - 300
if len(self.result) < 300:
self.result.append(date)
if len(self.result) >= 300:
print(self.result)         # (1)
self.result = []
#   def print_result(self, result):        # remove this
#       print(result)                      #

当调用:

aaa = Systembox()
print(aaa.result)        # (2) if you really need to know its status
# but it should be `[]` because `aaa` was just created
# with empty `result`, as defined in `__init__()`

记住(1)只在len(self.result) >= 300时执行。您的初始result是空的,所以它可能需要一些操作来输出一些东西。

相关内容

  • 没有找到相关文章

最新更新