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/2001-September/017531.html below:

[Python-Dev] why doesn't print pass unicode strings on to the file object?

[Python-Dev] why doesn't print pass unicode strings on to the file object?Martin von Loewis loewis@informatik.hu-berlin.de
Tue, 18 Sep 2001 18:21:02 +0200 (MEST)
> > _fields = {'encode':0,'decode':1,'reader':2,'writer':3}
> > class CodecInfo(tuple):
> >     __dynamic__ = 0
> >     def __getattr__(self, name):
> >         try:
> >             return self[_fields[name]]
> >         except KeyError:
> >             raise AttributeError, name
> 
> You want to change that raise statement into
> 
>               return tuple.__getattr__(self, name)
> 
> Remember, new-style __getattr__ *replaces* the built-in getattr
> operation

Originally, I had _fields as a class attribute, and was using
self._fields inside getattr, which caused a StackOverflow. I could not
figure out why it wouldn't just find _fields in the class before
invoking __getattr__...

> (I'm still considering whether this is too backwards incompatible; we
> could have two getattr hooks, one old-style and one new-style.)

So far, it is not really incompatible, since it only applies to
new-style classes. It is confusing to long-time users, so it deserves
documentation.

Regards,
Martin




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