Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Documenting python script entry (__name__ == '__main__') using sphinx

Is there a way, ideally using autodoc, to get sphinx to document a Python script? The section of the script I want documented is the portion protected by:

if __name__ == '__main__':

i.e. the bit that only runs if the module is used as a script instead of being imported.

like image 996
Papadeltasierra Avatar asked Jul 05 '26 18:07

Papadeltasierra


1 Answers

You should extract the code in that block into a function, with a docstring, and call that function from the block.

like image 69
Daniel Roseman Avatar answered Jul 07 '26 06:07

Daniel Roseman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!