Skip to content

Instantly share code, notes, and snippets.

@kmerenkov
Created July 7, 2010 18:44
Show Gist options
  • Save kmerenkov/467079 to your computer and use it in GitHub Desktop.
Save kmerenkov/467079 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
class A(object):
def do(self, x):
print ' A.foo(%s)' % (x,)
class B(object):
def do(self, x):
print ' B.foo(%s)' % (x,)
for x in xrange(0, 10):
def _foo(self):
self.do(x)
setattr(A, 'do_%d' % x, _foo)
def _bar(self, arg=x):
self.do(arg)
setattr(B, 'do_%d' % x, _bar)
print 'A:'
a = A()
for f in dir(a):
if f.startswith('do_'):
getattr(a, f)()
print 'B:'
b = B()
for f in dir(b):
if f.startswith('do_'):
getattr(b, f)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment