Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3244 Widoki
class CommandType(type):
  def __init__(cls, name, bases, attrs):
  super(CommandType, cls).__init__(name, bases, attrs)
  name = getattr(cls, name, cls.__name__.lower())
  cls.name = name
  if name != 'command':
commands[name] = cls

Command = CommandType('Command', (object,), {'run': lambda self, args: None})

class Help(Command):
  """Display the list of available commands"""
  def run(self, args):
  print("Available commands:\n")
  names = list(commands)
  padding = max([len(k) for k in names]) + 2
  for k in sorted(names):
  name = k.ljust(padding, ' ')
  doc = (commands[k].__doc__ or '').strip()
  print(" %s%s" % (name, doc))
  print("\nUse '%s <command> --help' for individual command help." % sys.argv[0].split(os.path.sep)[-1])
Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
4
lut 25
506
1
paź 23
754
1
lip 23
1724
0
sty 22
2376
1
cze 23
2759