On 13/02/2007 7.39, Martin v. Löwis wrote:

> And again. Apparently, people favor hasattr over catching 
> AttributeError. I'm not sure why this is - 

Because the code becomes longer, unless you want to mask other exceptions:


  name = 'http_error_%d' % errcode
-if hasattr(self, name):
-    method = self.(name)
+try:
+    method = self.(name)
+except AttributeError:
+    pass
+else:
      if data is None:
          result = method(url, fp, errcode, errmsg, headers)
      else:
          result = method(url, fp, errcode, errmsg, headers, data)
      if result: return result
  return self.http_error_default(url, fp, errcode, errmsg, headers)

-- 
Giovanni Bajo

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to