Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #54815

Re: Convert namedtuple to dictionary

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.032
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'indeed,': 0.09; 'underscore': 0.09; 'wrote': 0.14; '"private"': 0.16; '-tkc': 0.16; 'attribute.': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'namedtuple': 0.16; 'subject:Convert': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'documented': 0.24; 'define': 0.26; '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; 'but': 0.35; 'charset:us-ascii': 0.36; 'starting': 0.37; 'convention': 0.38; 'window': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'field': 0.63; 'life': 0.66; 'here': 0.66; 'private.': 0.84; 'received:50.22': 0.84; 'use"': 0.91; '2013': 0.98
Date Thu, 26 Sep 2013 06:51:41 -0500
From Tim Chase <python.list@tim.thechases.com>
To python-list@python.org
Subject Re: Convert namedtuple to dictionary
In-Reply-To <52438924$0$30000$c3e8da3$5496439d@news.astraweb.com>
References <635a3b46-3150-409f-8a9d-002af18fb734@googlegroups.com> <mailman.325.1380152379.18130.python-list@python.org> <52438924$0$30000$c3e8da3$5496439d@news.astraweb.com>
X-Mailer Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
X-Get-Message-Sender-Via boston.accountservergroup.com: none
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.352.1380196196.18130.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1380196196 news.xs4all.nl 15992 [2001:888:2000:d::a6]:58158
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:54815

Show key headers only | View raw


On 2013-09-26 01: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

Well dang if "leading underscore suggests private/internal use"
convention got tossed out the window here :)

But indeed, they are in the docs, so (to the OP), use _asdict() and
make life easy.

-tkc


Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Convert namedtuple to dictionary tripsvt@gmail.com - 2013-09-25 15:45 -0700
  Re: Convert namedtuple to dictionary Tim Chase <python.list@tim.thechases.com> - 2013-09-25 18:41 -0500
    Re: Convert namedtuple to dictionary Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-26 01:08 +0000
      Re: Convert namedtuple to dictionary MRAB <python@mrabarnett.plus.com> - 2013-09-26 02:15 +0100
      Re: Convert namedtuple to dictionary Terry Reedy <tjreedy@udel.edu> - 2013-09-25 21:45 -0400
      Re: Convert namedtuple to dictionary Tim Chase <python.list@tim.thechases.com> - 2013-09-26 06:51 -0500
  Re: Convert namedtuple to dictionary MRAB <python@mrabarnett.plus.com> - 2013-09-26 00:52 +0100
  Re: Convert namedtuple to dictionary Ned Batchelder <ned@nedbatchelder.com> - 2013-09-25 20:15 -0400
  Re: Convert namedtuple to dictionary Steven D'Aprano <steve@pearwood.info> - 2013-09-26 03:48 +0000
  Re: Convert namedtuple to dictionary Peter Otten <__peter__@web.de> - 2013-09-26 08:47 +0200

csiph-web