Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'say,': 0.05; 'turtle': 0.07; 'namespace': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'jan': 0.12; 'b=2)': 0.16; 'does,': 0.16; 'enough.': 0.16; 'finney': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:object': 0.16; 'subject:simple': 0.16; 'subject:type': 0.16; 'write,': 0.16; 'files.': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'module': 0.19; 'file,': 0.19; 'projects,': 0.19; '>>>': 0.22; 'import': 0.22; 'aug': 0.22; 'header:User-Agent:1': 0.23; 'class.': 0.26; 'right.': 0.26; 'asking': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'lines': 0.31; '>>>>': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'writes:': 0.31; 'class': 0.32; 'common': 0.35; 'but': 0.35; 'instances': 0.36; 'should': 0.36; 'wrong': 0.37; 'too': 0.37; 'ben': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'received:71': 0.39; 'subject:" ': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'ian': 0.60; 'worry': 0.60; 'tell': 0.60; 'august': 0.61; 'new': 0.61; 'name': 0.63; 'skip:n 10': 0.64; 'fact,': 0.69; 'behavior': 0.77; 'hood': 0.84; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Correct type for a simple "bag of attributes" namespace object Date: Sat, 02 Aug 2014 22:43:53 -0400 References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-71-175-90-87.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1407033906 news.xs4all.nl 2957 [2001:888:2000:d::a6]:55921 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75575 On 8/2/2014 8:59 PM, Ian Kelly wrote: > On Sat, Aug 2, 2014 at 2:46 PM, Mark Summerfield wrote: >> On Saturday, 2 August 2014 20:58:59 UTC+1, Ben Finney wrote: >>> Steven D'Aprano writes: >>> >>>> If you need instances which carry state, then object is the wrong >>>> class. >> >> Fair enough. >> >>> 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) >> >> This is too much for children (& beginners). >> >> But perhaps what I should be asking for is for a new built-in that does what types.SimpleNamespace() does, so that without any import you can write, say, >> >> foo = namespace(a=1, b=2) >> # or >> bar = namespace() >> bar.a = 1 >> >> where under the hood namespace has the same behavior as types.SimpleNamespace(). >> >> Naturally, I understand that adding a new name is a big deal and may be too much to ask for beginners. > > from types import SimpleNamespace as namespace > > Just have them put that at the top of each file, and tell them not to > worry about what it does. In fact, for the original usecase, put it in a 'template file' that also includes a turtle import. For one of my projects, I have @template with several lines of boilerplate that I use for new files. -- Terry Jan Reedy