我想在多个模块中使用以下类,而不需要log = InitLog()
在每个模块中。我需要能够log
跨多个模块使用一个定义的类变量(在本例中)。在不彻底改变我当前的代码的情况下,最好的方法是什么。谢谢
import os
import sys
import pdb
import fileinput
import Tools
class InitLog:
def __init__(self):
pass
def setLaws(self):
self.sound = 'off'
self.engine = 'goo.txt'
def Update(self):
while Tools.Locked.State.LogAddress == True: pass
Tools.Locked.State.LogAddress = True
try: os.remove(path + '/' + self.dest + '/init.log')
except: pass
summery = 'sound: ' + self.sound + '\n'
summery += 'engine: ' + self.engine + '\n'
path = os.getcwd()
if not os.path.exists(self.dest): os.makedirs(self.dest)
if os.path.isfile(path + '/' + self.dest + '/init.log') == True: os.remove(path + '/' + self.dest + '/init.log')
with open (path + '/' + self.dest + '/init.log', mode='a', encoding='utf-8') as a_file:
a_file.write(summery)
Tools.Locked.State.LogAddress = False
Tools.Locked.State.LogAddress = False
log = InitLog()
log.setLaws()
log.sound = 'on'
log.Update()