# HG changeset patch # User Jeff Hammel # Date 1414707749 25200 # Node ID cd9d65e6e2abd3fb7a314ef102ff6843317034a2 # Parent d6f659169b4973bfd265a06b296391cb70993865 monkeypatch example diff -r d6f659169b49 -r cd9d65e6e2ab python/example/monkeypatch.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/example/monkeypatch.py Thu Oct 30 15:22:29 2014 -0700 @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import argparse +import sys + +__all__ = ['main'] + +class ExampleClass(object): + def __init__(self, to_patch): + if to_patch: + self.output = lambda x, y: 'Patched!' + def output(self, x, y): + return '[{}] "{}"'.format(x, y) + + +if __name__ == '__main__': + obj = ExampleClass(False) + print (obj.output(1, 2)) + newobj = ExampleClass(True) + print (newobj.output(3, 4))