On Jul 8, 2:18 pm, [EMAIL PROTECTED] wrote: > Hello all, > > Imaybe someone can help me with this question. > Is there a direct way of accessing an object instance, if all I know > is the value of one of its attributes? > The object is part of a list of objects, and I would like to pick the > object directly by using this attribute value, instead of going > through the list and checking if each objects attribute value is the > one I am looking for. > > Thank you in advance
I'd set up a dict as a lookup table, assuming the attribute values are unique per object. list_of_objects = (obj1, obj2, obj3, obj4); obj_lookup_by_attr = {}; for obj in list_of_objects: obj_lookup_by_attr.set(obj.attr, obj) [...] obj = obj_lookup_by_attr.get(attr_val, None); if (obj): [...] -- http://mail.python.org/mailman/listinfo/python-list