Frage

I'm not even really sure what these things are officially called, though, Python has metadata, usually at the top of the module files such as __version__ = '0.1'.

How can I find a list of all of the ones supported by PyDoc?

War es hilfreich?

Lösung

Any top-level private globals following a particular naming convention will be included under the Data section generated by Pydoc:

  • All normal global variables are displayed there – you can see this simply by running pydoc on a module with some global variables that is otherwise empty.
  • "Special" names are displayed (but not private names): names like __SomeClass__ or __a_special_variable__ will be displayed, but names like __this_is_private will not.
  • Named tuples are displayed, as is anything that matches the pattern that specifies them: the object's name starts with _ and the object has a _fields attribute (i.e. it has public fields).

There are exceptions to these basic rules; names in the reserved list do not get the same treatment:

{'__author__', '__builtins__', '__cached__', '__credits__',
 '__date__', '__doc__', '__file__', '__initializing__',
 '__loader__', '__module__', '__name__', '__package__',
 '__path__', '__qualname__', '__slots__', '__version__'}

Pydoc will automatically build distinct sections for the __version__, __date__, __author__, and __credits__. The others are "redundant or internal" (e.g. __name__ and __package__ are assigned to their own sections, but Pydoc will also generate those fields automatically whether you set them or not).

All of this can be found by browsing the source, but there doesn't appear to be any other single place compiling this information — or at least, not one that ranks well in Google.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top