下面是一段非常簡單的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也可用於查詢很多你想要的東西