当print语句位于python中的类内时,如何仅打印一次语句

问题描述

codeList = []
code = ''

class codeInitiator():

    def __init__(self):
        self.code = code 
        
    def codeGenerator(self):
        #this function is too long but what is basically does is generate random code using randint etc 
        #and assigns it to the self.code variable.

        codeNoter()

    def codeNoter(self):

        codeList.append(self.code) 
        print(codeList)

    def execProcesses(self):
        
        self.codeGenerator()


a = codeInitiator()
b = codeInitiator()
c = codeInitiator()
a.execProcesses()
b.execProcesses()
c.execProcesses()

这里的问题是该列表被打印三次,第一次使用一个代码,第二次使用第一和第二代码,第三次使用第一,第二和较新的第三代码。我想要它,以便列表仅打印一次,这样它一次包含所有代码,而不是每次都包含。我尝试使用“将+1加到变量中并使用条件语句”的方法,但是它仍然不起作用。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)