annotate python/example/monkeypatch.py @ 923:b25fbb9257ec

Breeze GTK theme
author Jeff Hammel <k0scist@gmail.com>
date Thu, 14 Nov 2024 09:30:28 -0800
parents cd9d65e6e2ab
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
718
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 import argparse
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 import sys
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 __all__ = ['main']
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 class ExampleClass(object):
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 def __init__(self, to_patch):
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11 if to_patch:
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 self.output = lambda x, y: 'Patched!'
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 def output(self, x, y):
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 return '[{}] "{}"'.format(x, y)
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 if __name__ == '__main__':
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18 obj = ExampleClass(False)
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 print (obj.output(1, 2))
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 newobj = ExampleClass(True)
cd9d65e6e2ab monkeypatch example
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21 print (newobj.output(3, 4))