On Thu, Nov 21, 2002 at 01:51:15PM +0100, Just van Rossum wrote: > I sometimes use an idiom like > > def dictfromkeywords(**kwargs): > return kwargs > > d = dictfromkeywords( > akey = 12, > anotherkey = "foo", > ...etc. > ) I assume that the motive is to get rid of the quotes around the key and conceptually treat it as a "symbol" rather than as a string. If that is the case it could apply to access as well as initialization. class record(dict): def __init__(self, __initfrom=(), **kw): self.__dict__ = self dict.__init__(self, __initfrom) self.update(kw) def __repr__(self): return "%s(%s)" % (self.__class__.__name__, ', '.join(['%s=%s' % (k, repr(v)) for k,v in self.items()])) Fields can be accessed as either items or attributes of a record object. Oren
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