Carl Banks wrote: > In fact a lot of Pythonistas recommend this way over the > alternative, even when you don't have to. For example, a lot of people > recommend this: > > try: > name = record.name > except AttributeError: > name = "Freddy" > > instead of this: > > if hasattr(record,"name"): > name = record.name > else: > name = "Freddy" > >
In this specific case, either of these would be better written as: name = getattr(record, 'name', 'Freddy') -- http://mail.python.org/mailman/listinfo/python-list