pydoc さわってみた
モジュールのドキュメントが見れたり、簡単なドキュメントが作れるらしいよpydoc
使い方
ターミナル立ち上げて
$ python Python 2.7.10 (default, Jul 14 2015, 19:46:27) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
ここでhelp()を入力すると
>>> help() Welcome to Python 2.7! This is the online help utility. If this is your first time using Python, you should definitely check out the tutorial on the Internet at http://docs.python.org/2.7/tutorial/. Enter the name of any module, keyword, or topic to get help on writing Python programs and using Python modules. To quit this help utility and return to the interpreter, just type "quit". To get a list of available modules, keywords, or topics, type "modules", "keywords", or "topics". Each module also comes with a one-line summary of what it does; to list the modules whose summaries contain a given word such as "spam", type "modules spam". help>
ってなる。
そんで、例えばosモジュールが見たかったら
help> os
でEnter押すと
Help on module os: NAME os - OS routines for NT or Posix depending on what system we're on. FILE /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py MODULE DOCS http://docs.python.org/library/os DESCRIPTION This exports: - all functions from posix, nt, os2, or ce, e.g. unlink, stat, etc. - os.path is one of the modules posixpath, or ntpath - os.name is 'posix', 'nt', 'os2', 'ce' or 'riscos' - os.curdir is a string representing the current directory ('.' or ':') - os.pardir is a string representing the parent directory ('..' or '::') - os.sep is the (or a most common) pathname separator ('/' or ':' or '\\') - os.extsep is the extension separator ('.' or '/') - os.altsep is the alternate pathname separator (None or '/') - os.pathsep is the component separator used in $PATH etc - os.linesep is the line separator in text files ('\r' or '\n' or '\r\n') ...
って出てくる。
例えば自分の作ったコード
# -*-coding:utf-8-*- """ 1 コメント """ __author__ = "My_Name" TEST = "HELLO" class Test(): """ 2 コメント """ def test(self): """ 3 コメント """ pass if __name__ == '__main__': print "Hello World!"
として
help> test
こうすると
test - 1 コメント FILE /Users/user/Programming/python/doc/test.py CLASSES Test class Test | 2 コメント | | Methods defined here: | | test(self) | 3 コメント DATA TEST = 'HELLO' __author__ = 'My_Name' AUTHOR My_Name
こんな感じになる。
ちなみに
pydoc test
としたら直接見れる。
ドキュメント作成
オプションをつけるとhtmlファイルが生成される。
pydoc -w test
とすると
ってなる。
すべてのpythonファイルに適用したかったら
for i in `ls | cut -d "." -f 1` do pydoc -w $i done
って書くとできる。
少し雑だけど。