On Thu, 11 Dec 2008 21:56:19 +0000, Alan Gauld wrote:

> "Bryan Fodness" <bryan.fodn...@gmail.com> wrote
> 
>>I am trying to change values in a file.  The following code does not
>>seem to
>> find the attribute.
>>
>> def anonymize(obj, attr):
>>    try:
>>        obj.attr = 'Anonymize'
>>    except AttributeError:
>>        pass
> 
> This code is looking for an attribute of obj called attr It is not using
> the name of attr stored in the attr parameter.
> 
> To do that you will need to use the setattr function.
> 
> HTH

I don't think you'll even need setattr (for the piece of code given), 
because anonymize receives a fixed string. If that code is part of more 
complex code where the string might be anything setattr might be needed 
though.

What are you trying to do though?

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to