Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!roy From: Roy Smith Newsgroups: comp.lang.python Subject: Re: Correct type for a simple “bag of attributes” namespace object Date: Sun, 03 Aug 2014 13:44:14 -0400 Organization: PANIX Public Access Internet and UNIX, NYC Lines: 27 Message-ID: References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <857g2qd5oc.fsf_-_@benfinney.id.au> NNTP-Posting-Host: localhost X-Trace: reader1.panix.com 1407087854 24149 127.0.0.1 (3 Aug 2014 17:44:14 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Sun, 3 Aug 2014 17:44:14 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Xref: csiph.com comp.lang.python:75614 In article , Mark Lawrence wrote: > On 02/08/2014 20:58, Ben Finney wrote: > > Steven D'Aprano writes: > > > >> If you need instances which carry state, then object is the wrong > >> class. > > > > Right. The ‘types’ module provides a SimpleNamespace class for the > > common “bag of attributes” use case:: > > > > >>> import types > > >>> foo = types.SimpleNamespace() > > >>> foo.x = 3 > > >>> foo > > namespace(x=3) > > > > > > > > A slight aside but from the link "SimpleNamespace may be useful as a > replacement for class NS: pass." I'm not quite sure how that class > definition is meant to read, other than guessing that NS stands for > NameSpace, any ideas? Trivia: argparse.ArgumentParser().parse_args() returns a Namespace.