使用PYTHON3.8
期望:成功加载register.command
#tell.py
import bin.register
class tell:
def __init__(self):
bin.register.register.adder(tell)
#commands为[<class '__main__.tell'>]
tell()
#register.py
class register:
commands = []
@staticmethod
def getter():
return register.commands #被tell调用时为[<class '__main__.tell'>]
@staticmethod
def adder(item):
register.commands +=[item] #被tell调用时为[<class '__main__.tell'>]
@staticmethod
def setter(list1):
register.commands = list1
# main.py
from bin.register import register
for i in os.listdir("D:/Flyer1.0/lib/command/"): #
if os.path.isfile("D:/Flyer1.0/lib/command/"+i) and i.endswith('.py'): #获得D:\Flyer1.0\lib\command\下所有的py文件并运行
os.system(os.path.join("D:/Flyer1.0/lib/command/",i)) #结果:tell.py
while True:
for i in register.commands: # 在register中的command列表 **逻辑错误:command为[]**
ans = input("/Flyer1.0/run>").split(' ',1)
i.run_command(ans[1])
只有在main.py的第二个for循环中有问题(command为空)