[Tutor] getattr()

bob gailer bgailer at gmail.com
Wed Aug 4 22:40:50 CEST 2010


class A:
   def call_by_name(self, func, data):
     f = A.__dict__.get(func, self.output_text)
     return f(data)
   def output_text(self, data):return data
   def output_hex(self, data):return '\\x' + data
a = A()
data = 'bar'
print a.call_by_name('output_text', data)
print a.call_by_name('output_hex', data)
print a.call_by_name('foo', data)

-- 
Bob Gailer
919-636-4239
Chapel Hill NC



More information about the Tutor mailing list