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/071048.html below:

[Python-Dev] Summary of "dynamic attribute access" discussion

[Python-Dev] Summary of "dynamic attribute access" discussionGeorg Brandl g.brandl at gmx.net
Tue Feb 13 18:11:37 CET 2007
Martin v. Löwis schrieb:
> Anthony Baxter schrieb:
>>> and the "wrapper class" idea of Nick Coghlan:
>>>    attrview(obj)[foo]
>> 
>> This also appeals - partly because it's not magic syntax <wink>
> 
> I also like this. I would like to spell it attrs, and
> I think its specification is
> 
> class attrs:
>    def __init__(self, obj):
>      self.obj = obj
>    def __getitem__(self, name):
>      return getattr(self.obj, name)
>    def __setitem__(self, name, value):
>      return setattr(self.obj, name, value)
>    def __delitem__(self, name):
>      return delattr(self, name)
>    def __contains__(self, name):
>      return hasattr(self, name)
> 
> It's so easy people can include in their code for backwards
> compatibility; in Python 2.6, it could be a highly-efficient
> builtin (you still pay for the lookup of the name 'attrs',
> of course).

I fear people will confuse vars() and attrs() then.

Georg

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