答えて
pydocはdocstring内の "構造化"要素を認識せず、docstringをそのまま出力します。例については、PEP 0257を参照してください。
あなたが「フォーマットした」ドキュメントをしたい場合は、例えば機能のための
パラメータは関数ドキュメンテーション文字列で文書化する必要がある、などSphinxとして、別のドキュメントジェネレータを使用する必要があります。ここでthis answerから取った例である:あなたがより多くのパラメータ記述子を持つ再編テキストを利用したい場合はここで
"""
This example module shows various types of documentation available for use
with pydoc. To generate HTML documentation for this module issue the
command:
pydoc -w foo
"""
class Foo(object):
"""
Foo encapsulates a name and an age.
"""
def __init__(self, name, age):
"""
Construct a new 'Foo' object.
:param name: The name of foo
:param age: The ageof foo
:return: returns nothing
"""
self.name = name
self.age
def bar(baz):
"""
Prints baz to the display.
"""
print baz
if __name__ == '__main__':
f = Foo('John Doe', 42)
bar("hello world")
は別の、より明示的な例であり、このよう:type param:
や:rtype:
としてfrom here
"""
The ``obvious`` module
======================
Use it to import very obvious functions.
:Example:
>>> from obvious import add
>>> add(1, 1)
2
This is a subtitle
-------------------
You can say so many things here ! You can say so many things here !
You can say so many things here ! You can say so many things here !
You can say so many things here ! You can say so many things here !
You can say so many things here ! You can say so many things here !
This is another subtitle
------------------------
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
"""
def add(a, b):
"""
Adds two numbers and returns the result.
This add two real numbers and return a real result. You will want to
use this function in any place you would usually use the ``+`` operator
but requires a functional equivalent.
:param a: The first number to add
:param b: The second number to add
:type a: int
:type b: int
:return: The result of the addition
:rtype: int
:Example:
>>> add(1, 1)
2
>>> add(2.1, 3.4) # all int compatible types work
5.5
.. seealso:: sub(), div(), mul()
.. warnings:: This is a completly useless function. Use it only in a
tutorial unless you want to look like a fool.
.. note:: You may want to use a lambda function instead of this.
.. todo:: Delete this function. Then masturbate with olive oil.
"""
return a + b
あなたは(GoogleまたはNumpyなど)、のような異なるdocstring形式を使用することもできます。を使用して、ドキュメントストリングをより明確にします。
希望すると便利です。
ありがとうございます。私はすでに最初のdocstringを試しました。しかし、:paramはpydocによって "認識"されず、生成されたhtml文書に他のコメントとして表示されます。 – PatriceG
Pydocはdocstring中の "構造化"要素を認識せず、docstringをそのまま出力します。例については、[PEP 0257](https://www.python.org/dev/peps/pep-0257/)を参照してください。 この種の機能が必要な場合は、上記のように別のドキュメントジェネレータを使用する必要があります。 混乱して申し訳ありませんが、私は自分の答えを編集します – Ire
最後に答えは "それはpydocでは機能しません。右 ? – PatriceG
別の例
#!/usr/bin/env python
"""
Module documentation
A small example of comments usage
"""
# regular comment,
# will not visible by pydoc
spam = 40
def square(x):
"""
this function will return square(x) value
:param x: any number
:return: example doc for return
"""
return x ** 2
import abc
class ListInherited:
"""
Class ListInherited doc example
This class use dir() function for list instance attributes
"""
def __init__(self, arg1):
"""
my constructor
:param arg1: example value
:return:
"""
self.arg1 = arg1
def __str__(self):
"""
to string conversion
:return:
"""
tup = (self.__class__.__name__, id(self), self.attr_names())
return '<Instance of %s, address %s:\n%s>' % tup
def attr_names(self):
"""
get attribute names
:return: string
"""
result = ''
for attr in dir(self):
if attr[:2] == '__' and attr[-2:] == '__': # skip "build-in"
result += '\t name %s=<>\n' % attr
else:
result += '\t name %s=%s\n' % (attr, getattr(self, attr))
return result
@staticmethod
def my_static_method(count):
"""
static method comment example
:param count:
:return:
"""
return "Hello, I'm static" * count
if __name__ == "__main__":
import test3
x = 33
y = test3.square(x)
print(test3.__doc__)
print(test3.square.__doc__)
instance = ListInherited(1)
print(instance.__doc__)
のpythonコンソールで
>>> import test3
>>> help(test3)
出力:[?パラメータ(複数可)と方法を文書化する方法]
Help on module test3:
NAME
test3
FILE
/home/mrdinkelman/PycharmProjects/testproject27/test3.py
DESCRIPTION
Module documentation
A small example of comments usage
CLASSES
ListInherited
class ListInherited
| Class ListInherited doc example
| This class use dir() function for list instance attributes
|
| Methods defined here:
|
| __init__(self, arg1)
| my constructor
| :param arg1: example value
| :return:
|
| __str__(self)
| to string conversion
| :return:
|
| attr_names(self)
| get attribute names
| :return: string
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| my_static_method(count)
| static method comment example
| :param count:
| :return:
FUNCTIONS
square(x)
this function will return square(x) value
:param x: any number
:return: example doc for return
DATA
spam = 40
ありがとうございます。しかし、help()によって ":param"キーワードが認識されていますか?他のコメントと同様に印刷されているようです。 – PatriceG
- 1. PyDocをJira Confluenceにインポートする方法
- 2. のPython pydoc
- 3. 共有オブジェクトのPyDoc
- 4. PyDocにユーザ定義ディレクトリへのドキュメント生成を指示する方法
- 5. キーボードショートカットでvs2010のXAMLコードをコメント/コメント解除する方法
- 6. コメントのジェリーコメントをバッチする方法は?
- 7. pydocとhelp()の違いは?
- 8. pythonでコメントを設定する方法
- 9. 「コメント」を「テーブル」に設定する方法
- 10. ワードプレスサイトにコメントを投稿する方法
- 11. FParsecでコメントを解析する方法
- 12. facebookにコメントを投稿する方法
- 13. フォルダにコメントを追加する方法
- 14. HTMLのコメントでバイパスする方法
- 15. ジャージークライアントへのコメントを縮める方法
- 16. HTMLのコメントを隠す方法
- 17. JavaScriptの代替コメント方法
- 18. NERDのコメントを使用して/コメントのpythonファイルのコメントを解除する方法
- 19. MATLAB変数にコメントする方法
- 20. pydocは矛盾していますか?
- 21. JIRA REST API 4.4 HTTParty投稿でコメントにコメントを追加する方法
- 22. ファンページのすべてのコメントを取得する方法
- 23. rubyのコードコメントとregexのマッチング方法は? '#コメント' をmacthする方法
- 24. Youtubeビデオからすべてのコメントを取得する方法
- 25. HttPartyを使用してFacebookのコメントを取得する方法
- 26. Djangoのコメントフレームワークを使用してコメントを投稿する方法
- 27. データベース内のリクエストに複数のコメントをリンクする方法は?
- 28. VB.NETの特定の行にリンクするコメントを書く方法
- 29. .storyファイル(JBehave)の複数の行をコメントする方法
- 30. 特定の単語の行をコメントする方法
の可能性のある重複した(HTTPS: //stackoverflow.com/questions/9195455/how-to-document-a-method-with-parameters) –
@ Steven Vascellaro。可能な重複とは対照的に、この質問はpydocライブラリに固有です。 – PatriceG