Mercurial > cgi-bin > hgweb.cgi > tincan
view tests/suite_12_methods/files/WEB-INF/lib/jsdict.py @ 72:e8b3b336e63e draft default tip
Update version.
author | David Barts <n5jrn@me.com> |
---|---|
date | Mon, 15 Jul 2019 13:17:48 -0700 |
parents | 88adf10be709 |
children |
line wrap: on
line source
#!/usr/bin/env python3 # -*- coding: utf-8 -*- class JSDict(dict): """ Make a dict that acts something like a JavaScript object, in that we can use both x["name"] and x.name to access something. Note that the latter method fails for keys like x["get"] that duplicate dict methods, and keys like x["1"] which are not legal Python identifiers. """ def __getattr__(self, name): return self[name] def __setattr__(self, name, value): self[name] = value def __delattr__(self, name): del self[name] @classmethod def from_dict(cls, d): return cls(d)