Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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; 'mrab': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'trailing': 0.09; 'underscore': 0.09; 'jan': 0.12; 'wrote': 0.14; "wouldn't": 0.14; '"private"': 0.16; '9:15': 0.16; 'attribute.': 0.16; 'clashes': 0.16; 'namedtuple': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:Convert': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'wed,': 0.18; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'certainly': 0.24; 'documented': 0.24; 'define': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'tim': 0.29; 'chase': 0.31; "d'aprano": 0.31; 'sep': 0.31; 'steven': 0.31; 'tuples': 0.31; 'url:python': 0.33; 'sense': 0.34; 'but': 0.35; 'url:org': 0.36; 'starting': 0.37; 'sometimes': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'embedded': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'users': 0.40; 'received:173': 0.61; 'such': 0.63; 'field': 0.63; 'more': 0.64; 'private.': 0.84; 'received:fios.verizon.net': 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Convert namedtuple to dictionary Date: Wed, 25 Sep 2013 21:45:31 -0400 References: <635a3b46-3150-409f-8a9d-002af18fb734@googlegroups.com> <52438924$0$30000$c3e8da3$5496439d@news.astraweb.com> <52438AC6.9060206@mrabarnett.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0 In-Reply-To: <52438AC6.9060206@mrabarnett.plus.com> 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380159943 news.xs4all.nl 15892 [2001:888:2000:d::a6]:47341 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54774 On 9/25/2013 9:15 PM, MRAB wrote: > On 26/09/2013 02:08, Steven D'Aprano wrote: >> On Wed, 25 Sep 2013 18:41:25 -0500, Tim Chase wrote about namedtuple: >> >>> While it uses the "private" member-variable "_fields", you can do >> >> It's not actually private! >> >> namedtuple is documented as an exception to the rule that methods >> starting with a single leading underscore are private. Named tuples >> define three public methods and one data attribute. In order to avoid >> clashing with field names, they start with a single underscore, but they >> are documented as public: >> >> _make >> _asdict >> _replace >> _fields >> >> >> http://docs.python.org/2/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields >> >> > Wouldn't it have made more sense to have a trailing underscore instead? Users might use such to avoid clashes with keywords and builtins: 'print_', 'id_', 'as_', and will certainly sometimes use embedded _. -- Terry Jan Reedy