def exit(self)sys exit( class menuitemdef click(self)self command(window window(menu_item menuitem(menu_item command window exit now that looks lot more like python at first glanceit looks like we've removed the command pattern altogetherand we've tightly connected the menu_item and window classes but if we look closerwe find there is no tight coupling at all any callable can be set up as the command on the menuitemjust as before and the window exit method can be attached to any invoker most of the flexibility of the command pattern has been maintained we have sacrificed complete decoupling for readabilitybut this code isin my opinionand that of many python programmersmore maintainable than the fully abstracted version of coursesince we can add __call__ method to any objectwe aren' restricted to functions the previous example is useful shortcut when the method being called doesn' have to maintain statebut in more advanced usagewe can use this code as wellclass documentdef __init__(selffilename)self filename filename self contents "this file cannot be modifieddef save(self)with open(self filename' 'as filefile write(self contentsclass keyboardshortcutdef keypress(self)self command(class savecommanddef __init__(selfdocument)self document document def __call__(self)