Hi all, I have a question about the following lines of code: >>> class Foo: ... bar = 'bar' ... >>> # is it better this >>> def te(attribute): ... try: ... print getattr(c, attribute) ... except AttributeError: ... return None >>> # >>> # or this? >>> def h_a(attribute): ... if hasattr(c, attribute): ... return getattr(c, attribute) ... else: ... return None ...
Generally, to handle potentially erroneus situations, which pattern is most correct to use? TIA _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor