A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2007-February/071033.html below:

[Python-Dev] New syntax for 'dynamic' attribute access

[Python-Dev] New syntax for 'dynamic' attribute accessGiovanni Bajo rasky at develer.com
Tue Feb 13 11:46:28 CET 2007
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

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4