class CommandQueue(): queue = [] @staticmethod def append(cmd): CommandQueue.queue.append(cmd) @staticmethod def process(): for c in CommandQueue.queue: c.execute() CommandQueue.queue = [] class MetaCommand(type): def __init__(self, name, bases, dct): """If we want to do something when the class is *declared*, it goes here.""" super(MetaCommand, self).__init__(name, bases, dct) def __call__(self, *args, **kwargs): """We want to add the command instance to the queue, so we do it here.""" instance = super(MetaCommand, self).__call__(*args, **kwargs) CommandQueue.append(instance) class BaseCommand(): __metaclass__ = MetaCommand def execute(self): pass class NickCommand(BaseCommand): def __init__(self, nick): self.nick = nick def execute(self): print "NICK %s" % self.nick class KickCommand(BaseCommand): def __init__(self, channel, nick): self.channel = channel self.nick = nick def execute(self): print "KICK %s %s" % (self.channel, self.nick) NickCommand("test") KickCommand("#liek", "Phix") CommandQueue.process()