Convert namedtuple to dictionary

Terry Reedy tjreedy at udel.edu
Wed Sep 25 21:45:31 EDT 2013


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




More information about the Python-list mailing list