[Tutor] no attribute

Alan Gauld alan.gauld at btinternet.com
Thu Dec 11 22:56:19 CET 2008


"Bryan Fodness" <bryan.fodness at 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


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list