"Bryan Fodness" <[email protected]> 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

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to