Is there any way to get class flexibility, at least with some of the brevity of collections. namedtuple?
Just create an instance of the class and assign class attributes to it:
class Namespace(object): foo = 'bar'
and now Namespace.foo returns 'bar'
The style is bad in the script, but in the shell you can set several attributes separated by a semicolon:
>>> class NameSpace(object): foo = 'bar'; baz = {} >>> NameSpace.baz['quux'] = 'ni' >>> NameSpace.foo 'bar' >>> NameSpace.something = 'completely different'
... collections.namedtuple?
Well, the above is even more concise, but below is a bit like collections.namedtuple (makes you wonder where they got the idea from, right?):
>>> NameSpace = type('NameSpace', (object,), {'foo': 'bar', 'baz': {}}) >>> NameSpace.baz['quux'] = 'ni' >>> NameSpace.foo 'bar'
Aaron hall
source share