[Python-ideas] Docstrings for namedtuple
Serhiy Storchaka
storchaka at gmail.com
Wed Dec 12 20:57:58 CET 2012
On 12.12.12 21:35, Antoine Pitrou wrote:
> field_docs={'x': 'abscissa', 'y': 'ordinate'} perhaps?
This will force repeat the field names twice.
If we have such docs_dict, we can use it as:
field_names = ['x', 'y']
Point = namedtuple('Point', field_names,
field_docs=list(map(docs_dict.get, field_names)))
or as
Point = namedtuple('Point',
[(f, docs_dict.get(f)) for f in field_names])
In case of ordered dict it can be even simpler:
Point = namedtuple('Point', ordered_dict.keys(),
field_docs=list(ordered_dict.values()))
or
Point = namedtuple('Point', ordered_dict.items())
More information about the Python-ideas
mailing list