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


Groups > comp.lang.python > #54774

Re: Convert namedtuple to dictionary

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Convert namedtuple to dictionary
Date 2013-09-25 21:45 -0400
References <635a3b46-3150-409f-8a9d-002af18fb734@googlegroups.com> <mailman.325.1380152379.18130.python-list@python.org> <52438924$0$30000$c3e8da3$5496439d@news.astraweb.com> <52438AC6.9060206@mrabarnett.plus.com>
Newsgroups comp.lang.python
Message-ID <mailman.333.1380159943.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

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