class CommandManager:
def __init__(self):
self.commands = []
def add_command(self, command: Command):
if command is None:
return None
for target in self.commands:
if target.name is command.name:
return None
print(command.name, command.description, command.usage, command.min_arguments) # debug
self.commands.append(command)
return command
def get_command(self, name):
if name is None:
return None
for target in self.commands:
if name is target.name:
return target
return None
這段代碼有什麼問題?添加到數組中並在add_command
方法中查找它可以正常工作,但在get_command
中找不到它。沒有值是None
。在列表中搜索
不要用'is'比較字符串。 –
你有什麼建議? – kacperduras