Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pydoc supported python metadata such as __version__ = '0.1'

Tags:

python

pydoc

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?

like image 646
Matt Campbell Avatar asked Mar 16 '13 18:03

Matt Campbell


People also ask

What is metadata Python?

metadata, is a Python module for accessing and managing an item's metadata. You can explore information describing your maps and data and automate your workflows, particularly for managing standards-compliant geospatial metadata.

What does Pydoc input do?

The pydoc module automatically generates documentation from Python modules. The documentation can be presented as pages of text on the console, served to a web browser, or saved to HTML files.


1 Answers

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.

like image 194
Chris Krycho Avatar answered Oct 27 '22 04:10

Chris Krycho