kking1 发表于 2023-2-13 16:22:42

类里面的函数调用问题求助

class Task:
    image_window_list = []
    def setId(self,Id):
      self.Id = Id

    def setNoDownlink(self,NoDownlink):
      self.setNoDownlink = NoDownlink

    def setTaskRequest(self,task_request):
      self.setTaskRequest = task_request

    def setTaskProperty(self,task_property):
      self.setTaskProperty = task_property

    def setTarget(self,task_target):
      self.setTarget = task_target

    def getImageWindowList(self,window):
      self.getImageWindowList = Task.image_window_list.append(window)
   
a = Task()
window1 = 1
window2 = 2
print(type(window1))
print(type(window2))
a.getImageWindowList(window1)
a.getImageWindowList(window2)
print(a.image_window_list)



求问大佬,为啥a.getImageWindowList(window2)这一行会报TypeError: 'NoneType' object is not callable这个错误?

isdkz 发表于 2023-2-13 16:28:15

class Task:
    image_window_list = []
    def setId(self,Id):
      self.Id = Id

    def setNoDownlink(self,NoDownlink):
      self.setNoDownlink = NoDownlink

    def setTaskRequest(self,task_request):
      self.setTaskRequest = task_request

    def setTaskProperty(self,task_property):
      self.setTaskProperty = task_property

    def setTarget(self,task_target):
      self.setTarget = task_target

    def getImageWindowList(self,window):
      Task.image_window_list.append(window)                      # 这一行代码,你把 getImageWindowList 方法重新赋值了,而 append 的返回值是 None
   
a = Task()
window1 = 1
window2 = 2
print(type(window1))
print(type(window2))
a.getImageWindowList(window1)
a.getImageWindowList(window2)
print(a.image_window_list)

kking1 发表于 2023-2-13 17:18:06

isdkz 发表于 2023-2-13 16:28


那应该怎样把那个window2的值插进去呢?

isdkz 发表于 2023-2-13 17:19:21

kking1 发表于 2023-2-13 17:18
那应该怎样把那个window2的值插进去呢?

我改的那个代码你有运行了吗?那个就已经把 windows2 的值插进去了呀

kking1 发表于 2023-2-13 17:20:31

isdkz 发表于 2023-2-13 16:28


没重新赋值吧?只是把元素插入一个列表而已

kking1 发表于 2023-2-13 17:22:06

isdkz 发表于 2023-2-13 17:19
我改的那个代码你有运行了吗?那个就已经把 windows2 的值插进去了呀

没看到你改的那个代码额

kking1 发表于 2023-2-13 17:24:22

isdkz 发表于 2023-2-13 17:19
我改的那个代码你有运行了吗?那个就已经把 windows2 的值插进去了呀

哦,看到了,谢谢

isdkz 发表于 2023-2-13 17:24:35

kking1 发表于 2023-2-13 17:22
没看到你改的那个代码额

class Task:
    image_window_list = []
    def setId(self,Id):
      self.Id = Id

    def setNoDownlink(self,NoDownlink):
      self.setNoDownlink = NoDownlink

    def setTaskRequest(self,task_request):
      self.setTaskRequest = task_request

    def setTaskProperty(self,task_property):
      self.setTaskProperty = task_property

    def setTarget(self,task_target):
      self.setTarget = task_target

    def getImageWindowList(self,window):
      Task.image_window_list.append(window)                      # 这一行代码,你把 getImageWindowList 方法重新赋值了,而 append 的返回值是 None
   
a = Task()
window1 = 1
window2 = 2
print(type(window1))
print(type(window2))
a.getImageWindowList(window1)
a.getImageWindowList(window2)
print(a.image_window_list)

isdkz 发表于 2023-2-13 17:25:33

kking1 发表于 2023-2-13 17:20
没重新赋值吧?只是把元素插入一个列表而已

因为那个是我改了后的呀

你看看你没改之前的:

self.getImageWindowList = Task.image_window_list.append(window)
页: [1]
查看完整版本: 类里面的函数调用问题求助