如何在 Python 中记录字典?

Aka*_*sha 6 python dictionary python-sphinx

我正在从 xmls 中提取数据,并将它们放入 Elasticsearch。在临时步骤中,我有一个 dict,其中包含我想放入 Elasticsearch 的所有数据,我想将这些数据记录在案。最好的办法是把这个文档和 Sphinx 生成的代码放在一起。

class MyCustomParser(Parser):

  def _get_data(self):
    # this is what matters
    data = {
        #: Shows if commitlog is required or not
        "has_commitlog": self._xml_helper.has_attribute_enabled('.//require_commitlog'),
Run Code Online (Sandbox Code Playgroud)

我想要的是字典的键和上面的注释文档。dict 大约有 50 行,我想进一步扩展它。

我已经四处搜索,但找不到任何解决此问题的方法。我的想法是将 dict 更改为自定义的类似 dict 的对象,记录对象的属性,并在_get_data上面的方法中设置它们。我不喜欢这个想法的是它的冗长,而不是一个苗条的字典定义,我最终会得到类似的东西

MyCustomWhat(
  has_commitlog=self._xml_helper.has_attribute_enabled('.//require_commitlog'),
  ...
)
Run Code Online (Sandbox Code Playgroud)

你有什么想法在代码中记录这个字典的键?