如果我在Python控制台中处理一个对象,有没有办法查看该类可用的方法?
a = list()
print dir(a)
如果你真的想查看你对象所属类的方法:
a = list()
print dir(a.__class__)
另一种让您查看对象文档字符串的方法是使用内置函数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)
|
(...等等).
假设它的名称是"theobject": dir(theobject)
>>> 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.