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/2005-April/052877.html below:

[Python-Dev] Re: __except__ use cases

[Python-Dev] Re: __except__ use casesJohn J Lee jjl at pobox.com
Sun Apr 24 19:12:03 CEST 2005
On Sun, 24 Apr 2005, Nick Coghlan wrote:
[...]
> Seeing this example has convinced me of something. PEP 310 should use the 'with' 
> keyword, and 'expression block' syntax should be used to denote the 'default 
> object' semantics proposed for Python 3K. For example:
> 
> class Key2AttributeError(object):
>      def __init__(self, obj, attr):
>          self:
>              .obj_type = type(obj)
>              .attr = attr
>      def __except__(self, ex_type, ex_val, ex_tb):
>          if isinstance(ex_type, KeyError):
>               self:
>                   raise AttributeError("%s instance has no attribute %s"
>                                         % (.obj_type, .attr))
> 
> > # Somewhere else. . .
>      def __getattr__(self, name):
>          with Key2AttributeError(self, key):
>              self:
>                  return ._cache[key]
[...]

+1

Purely based on my aesthetic reaction, that is.  Never having used other
languages with this 'attribute lookup shorthand' feature, that seems to
align *much* more with what I expect than the other way around.  If 'with'
is used in other languages as the keyword for attribute lookup shorthand,
though, perhaps it will confuse other people, or at least make them frown
:-(


John
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