2011-02-01 5 views

답변

8

클래스에 의해, 당신은 실제로 당신이 가지고있는 인스턴스를 의미하는 경우, 당신은 단순히 디렉토리 사용할 수 있습니다 : 당신이 정말로 의미하는 경우

a = list() 
print dir(a) 

+0

감사합니다. 첫 번째 경우는 의미하지만 두 가지를 모두 아는 것이 좋습니다. –

0

는 이름이 "theobject"라고 개체의 클래스의 메서드를 참조하십시오

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

이 경우, 모두 같은 결과를 인쇄,하지만 파이썬은 매우 동적 인, 당신이 인스턴스에 새로운 방법을 첨부 상상할 수 있습니다, 수업에 반영되지 않은 채로.

파이썬을 배우고 있고 멋진 환경에서 리플렉션 기능의 이점을 얻으려면 ipython을 살펴 보시기 바랍니다. ipython 내부, 당신은

1

개체가 내장 된 기능 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.