• 写好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也可用于查询很多你想要的东西

  • 相关阅读:
    js··事件捕捉
    js中的Call()和apply()
    什么是变量提升?
    什么是作用域? 什么是作用域链?
    什么是原型链?
    js中this是什么?
    Js高级 事件冒泡
    Js高级 事件 对象
    Js高级 部分内容 面向对象
    工作期间的策划案总结(1)
  • 原文地址:https://www.cnblogs.com/wanzaixiaoxin/p/3152492.html
Copyright © 2020-2023  润新知