写好python的注释文档很容易


下面是一段非常简单的foo.py

#!usr/bin/env python

"""foo.py -- this is a demo"""

class Foo(object):
    """Foo - this is a empty class,to be developed"""

def printdoc(x):
    """bar(x) - to print the parameters 'x' """
    print x

在python中执行如下过程:
>>> import foo

通过__doc__属性访问模块、函数、类的文档
>>> foo.__doc__
'foo.py -- this is my first damo'
AttributeError: type object 'Foo' has no attribute '__doc'
>>> foo.Foo.__doc__
'Foo -- this is empty class,to be devloped'
>>> foo.bar.__doc__
"bar(x)- to print the para 'x'"

也可以通过内置函数help

>>> help(foo)
Help on module foo:

NAME
    foo - foo.py -- this is my first damo

FILE
    /django/foo.py

CLASSES
    __builtin__.object
        Foo

    class Foo(__builtin__.object)
     |  Foo -- this is empty class,to be devloped
     |
     |  Data and other attributes defined here:
     |
     |  __dict__ = <dictproxy object>
     |      dictionary for instance variables (if defined)
     |
     |  __weakref__ = <attribute '__weakref__' of 'Foo' objects>
     |      list of weak references to the object (if defined)

FUNCTIONS
    bar(x)
        bar(x)- to print the para 'x'

同样help也可用于查询很多你想要的东西


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM