
On Wed, Aug 3, 2011 at 11:49 PM, Herman Sheremetyev <herman@swebpage.com> wrote:
Both of them do the same thing as well as give access to the values using [] notation. There are probably other examples in third party libraries.
Sure. Another stdlib-ish example is Sphinx, which does it in sphinx.util.attrdict. And you can search google code for 'self.__dict__ = self', which reveals a particular(ly nasty) pattern for it with many instances. Devin On Wed, Aug 3, 2011 at 11:49 PM, Herman Sheremetyev <herman@swebpage.com> wrote:
On Thu, Aug 4, 2011 at 2:17 AM, dag.odenhall@gmail.com <dag.odenhall@gmail.com> wrote:
obj = object(foo=1, bar=lambda x: x) obj.foo
1 obj.bar(2) 2
Problem? :)
from argparse import Namespace obj = Namespace(foo=1, bar=lambda x: x) obj.foo 1 obj.bar(2) 2
Good find, who'd have ever thought to look in argparse for something like Namespace.. After some more poking around in the stdlib for __init__ methods that take keyword args I found:
plistlib.Dict and plistlib.Plist
Both of them do the same thing as well as give access to the values using [] notation. There are probably other examples in third party libraries.
-Herman _______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas