Automated testing

Revision as of 20:49, 5 May 2012 by 176.9.29.232 (talk) (Gustavo)

Better solution:class Product(object): def __init__(self, purcodt_id): self.id = purcodt_iddef make_property(prop): def getter(self): return api_obj.get_product_property(self.id, prop) return property(getter)for prop in ('price', 'attr'): setattr(Product, prop, make_property(prop))Reasons this is better: * You don’t break dir(product): it still shows the properties. * You get the AttributeError for free.If you want to support an arbitrary number of properties, it probably makes more sense to have a .get_property(prop) method, or to use .__getitem__ instead.