| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

Python help関数の使い方

提供: MyMemoWiki
ナビゲーションに移動 検索に移動

Python help関数の使い方

Python | 言語まとめ Python |

"対象"に調べたいオブジェクトを設定

  1. >>> help(対象)

ライブラリ等の場合、importしてから使用する

  1. >>> import fileinput
  2. >>> help(fileinput)
  3. Help on module fileinput:
  4.  
  5. NAME
  6. fileinput - Helper class to quickly write a loop over all standard input fi
  7. es.
  8.  
  9. FILE
  10. c:\python25\lib\fileinput.py
  11.   

組み込みオブジェクトのHELPを確認する

組み込みオブジェクト名称を取得
  1. >>> import pprint
  2. >>> pprint.pprint(dir(__builtins__))
  3. ['ArithmeticError',
  4. 'AssertionError',
  5. 'AttributeError',
  6. 'BaseException',
  7. 'DeprecationWarning',
  8. 'EOFError',
  9. 'Ellipsis',
  10. 'str'
  11. 'zip']
例えば、文字列型のHELPを確認
  1. >>>help(__builtins__.str)
  2. Help on class str in module __builtin__:
  3.  
  4. class str(basestring)
  5. | str(object) -> string
  6. |
  7. | Return a nice string representation of the object.
  8. | If the argument is a string, the return value is the same object.
  9. |
  10.  

オブジェクトではない場合、引用符で囲って使用する

  1. >>> help('print')
  2. ------------------------------------------------------------------------
  3.  
  4. 6.6 The print statement
  5.  
  6. print_stmt ::= "print" ([expression[1] ("," expression[2])* [","]
  7. | ">>" expression[3] [("," expression[4])+ [","])
  8.  
  9. Download entire grammar as text.[5]
  10.  
  11. print evaluates each expression in turn and writes the resulting object
  12. to standard output (see below). If an object is not a string, it is
  13.