[Tutor] getattr()

bob gailer bgailer at gmail.com
Wed Aug 4 22:08:42 CEST 2010


On 8/4/2010 4:04 PM, bob gailer wrote:
> On 8/4/2010 3:44 PM, Huy Ton That wrote:
>> Oh, that's right, I should have tried to example in the interpreter 
>> instead of in my head:P
>>
>> Say Bob,
>>
>> Is that the preferred method over something like:
>
> I would prefer to create a class and make these functions class methods.
>
> class A:
>   def output_text(self, data):return data
>   def output_hex(self, data):return '\\x' + data
>   def __getattr__(self, name):
>     return self.output_text
> a = A()
> data='bar'
> print a.output_text(data)
> print a.output_hex(data)
> print a.foo(data)
>
I just realized my answer does not accomodate your looking for the 
function by name. Please stand by....

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



More information about the Tutor mailing list