from prettyprinter import cpprint as pp
import os, time
print(os.uname())
pp(os.uname())
print(time.strptime("2000", "%Y"))
pp(time.strptime("2000", "%Y"))
One can detect whether a type is a "C-namedtuple" by checking that it is a tuple subclass with the additional fields n_fields, n_sequence_fields, and n_unnamed_fields. However, to the best of my knowledge, there is no simple API (at the Python-level) to list the field names in their order. One hack could be perhaps to build a new instance of the C-namedtuple by passing enough (i.e. n_fields) zeros to the constructor, then parsing the str() of the object...
Description
Some Python builtins, such as
os.uname
ortime.strptime
return a "C namedtuple" (per https://docs.python.org/3/c-api/tuple.html#struct-sequence-objects). prettyprinter's output for them is less than optimal:gives
One can detect whether a type is a "C-namedtuple" by checking that it is a tuple subclass with the additional fields n_fields, n_sequence_fields, and n_unnamed_fields. However, to the best of my knowledge, there is no simple API (at the Python-level) to list the field names in their order. One hack could be perhaps to build a new instance of the C-namedtuple by passing enough (i.e.
n_fields
) zeros to the constructor, then parsing the str() of the object...gives
What I Did
See above.