3
我从Exception派生最简单的类,看起来是这样的:简化类文档字符串
class Test(Exception):
'''
My Test class
'''
def __init__(self, param=None):
self.param = param
def __str__(self):
return 'Test representation'
def foo(self):
'''Perform a foo'''
print 'Fubar'
当我运行该模块的帮助(),我得到:
class Test(exceptions.Exception)
| My Test class
|
| Method resolution order:
| Test
| exceptions.Exception
| exceptions.BaseException
| __builtin__.object
|
| Methods defined here:
|
| __init__(self, param=None)
|
| __str__(self)
|
| foo(self)
| Perform a foo
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from exceptions.Exception:
|
| __new__ = <built-in method __new__ of type object>
| T.__new__(S, ...) -> a new object with type S, a subtype of T
|
| ----------------------------------------------------------------------
| Methods inherited from exceptions.BaseException:
|
| __delattr__(...)
| x.__delattr__('name') <==> del x.name
|
| __getattribute__(...)
| x.__getattribute__('name') <==> x.name
|
| __getitem__(...)
| x.__getitem__(y) <==> x[y]
|
| __getslice__(...)
| x.__getslice__(i, j) <==> x[i:j]
|
| Use of negative indices is not supported.
|
| __reduce__(...)
|
| __repr__(...)
| x.__repr__() <==> repr(x)
|
| __setattr__(...)
| x.__setattr__('name', value) <==> x.name = value
|
| __setstate__(...)
|
| __unicode__(...)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from exceptions.BaseException:
|
| __dict__
|
| args
|
| message
这是一种可怕的噪音,与课程文件无关。我如何压制这一切?
[编辑] 我想它更喜欢什么,如果类没有继承自Exception
喜欢我会得到:
class Test
| My Test class
|
| Methods defined here:
|
| __init__(self, param=None)
|
| __str__(self)
|
| foo(self)
| Perform a foo
这正是它应该做的。你想要什么? – jonrsharpe 2014-12-01 21:01:28
如果你只想要class'docstring,你可以'print Test .__ doc__'或者'print inspect.getdoc(Test)'。 – iCodez 2014-12-01 21:04:46
我希望它不会显示与基类相关的东西 – 2014-12-01 21:26:22