2011-02-01 7 views

答えて

8

クラスによって、あなたが実際にあなたが持っているインスタンスを意味している場合は、単にDIR使用することができます:あなたは本当にすることを意図している場合

a = list() 
print dir(a) 

+0

感謝を使用しています。最初のケースは私が意味していたものですが、両方を知ることは良いことです。 –

0

は、その名前が "theobject" と言いますあなたのオブジェクトのクラスのメソッドを参照してください。

a = list() 
print dir(a.__class__) 

その場合には、両方が同じ結果を印刷しますが、Pythonは、非常にダイナミックであること、あなたはインスタンスに新しいメソッドを取り付ける想像することができることに注意してください、それはクラスに反映されていません。

あなたがpythonを学んでいて、素晴らしい環境でリフレクション機能の恩恵を受けるには、ipythonを見てみることをお勧めします。 ipythonの中に、あなたは方法のタブ補完を取得/あなたがオブジェクトのためのドキュメンテーション文字列を見てみましょうになる別のアプローチは、等...(help()

>>> i = 1 
>>> help(type(i)) 
Help on class int in module __builtin__: 

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 base is zero, the proper base is guessed based on the 
| string content. If the argument is outside the integer range a 
| long object will be returned instead. 
| 
| Methods defined here: 
| 
| __abs__(...) 
|  x.__abs__() <==> abs(x) 
| 

組み込み関数を使用することです

0

あなたはタブ補完をしたい場合は、Ipython、またはSTDLIBのrlcompleter

>>> import rlcompleter 
>>> import readline 
>>> readline.parse_and_bind("tab: complete") 
>>> readline. <TAB PRESSED> 
readline.__doc__   readline.get_line_buffer( readline.read_init_file(
readline.__file__   readline.insert_text(  readline.set_completer(
readline.__name__   readline.parse_and_bind(
>>> readline.