开发者

Is it possible to create a python documentation when there are no classes?

开发者 https://www.devze.com 2023-03-20 13:22 出处:网络
I have many python files. Each file has functions. That\'s it.I don\'t do anything with classes. Will Sphinx开发者_高级运维 (or another documentation software) still create the documentation for it,

I have many python files.

Each file has functions. That's it. I don't do anything with classes.

Will Sphinx开发者_高级运维 (or another documentation software) still create the documentation for it, and if so, what will it look like?


Yes, of course. That's one of the many normal ways to program in Python. You don't have to use classes -- in fact, many of the modules that come with Python are just collections of functions. Any Python documentation tool will be prepared to deal with this.


Ideally, Python functions and classes are all documented in a specific way that the language (and documentation-generating software) can see, called a docstring. If you put a string immediately after every function definition, like this:

def double(number):
    """Returns number times 2. May behave poorly if number isn't actually a number"""
    return number * 2;

...then you can get the function double's docstring from double.__doc__.

For a more detailed description of how to write good docstrings, see PEP8. Search for "Documentation Strings" to skip to the part you care about.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号