help, dir
□未翻訳
□翻訳中
□翻訳完了(細田謙二)
■レビュー(Omi Chiba)
help, dir
Python言語には、組み込みおよびユーザ定義両方の現在のスコープにおいて、定義されたオブジェクトに関するドキュメントを取得する2つのコマンドが用意されています。
The Python language provides two commands to obtain documentation about objects defined in the current scope, both built-in and user-defined.
たとえば"1"というオブジェクトに関するhelpを尋ねることができます:
We can ask for help about an object, for example "1":
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
>>> help(1)
Help on int object:
class int(object)
| int(x[, base]) -> integer
|
| Convert a string or number to an integer, if possible. A floating point
| argument will be truncated towards zero (this does not include a string
| representation of a floating point number!) When converting a string, use
| the optional base. It is an error to supply a base when converting a
| non-string. If the argument is outside the integer range a long object
| will be returned instead.
|
| Methods defined here:
|
| __abs__(...)
| x.__abs__() <==> abs(x)
...
"1"は整数なので、intクラスとそのすべてのメソッドに関する説明が得られます。 上記の例では出力結果が長いため、切り取られています。
and, since "1" is an integer, we get a description about the int class and all its methods. Here the output has been truncated because it is very long and detailed.
同様に、dirコマンドを用いることで、"1"オブジェクトのメソッドのリストを得ることができます。
Similarly, we can obtain a list of methods of the object "1" with the command dir:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
>>> dir(1)
['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__',
'__delattr__', '__div__', '__divmod__', '__doc__', '__float__',
'__floordiv__', '__getattribute__', '__getnewargs__', '__hash__', '__hex__',
'__index__', '__init__', '__int__', '__invert__', '__long__', '__lshift__',
'__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', '__oct__',
'__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdiv__',
'__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__',
'__rlshift__', '__rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__',
'__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__',
'__str__', '__sub__', '__truediv__', '__xor__']