- 阅读权限
- 255
- 威望
- 1 级
- 论坛币
- 49655 个
- 通用积分
- 55.9937
- 学术水平
- 370 点
- 热心指数
- 273 点
- 信用等级
- 335 点
- 经验
- 57805 点
- 帖子
- 4005
- 精华
- 21
- 在线时间
- 582 小时
- 注册时间
- 2005-5-8
- 最后登录
- 2023-11-26
|
11楼
ReneeBK(未真实交易用户)
发表于 2017-2-12 08:34:23
|
- Listing 4-9. classInfo.py
- 1|def classInfo( Class, meth = None, attr = None, pad = '' ) :
- 2| print pad + str( Class )
- 3| prefix = pad + ' '
- 4| if type( meth ) == type( '' ) :
- 5| comma, line = '', '' + prefix
- 6| methods = [
- 7| n for n, v in vars( Class ).items()
- 8| if n.lower().find( meth.lower() ) > -1 and callable( v )
- 9| ]
- 10| methods.sort()
- 11| for m in methods :
- 12| if len( line + comma + m ) > 65 :
- 13| print line.replace( '|', '>' )
- 14| comma, line = '', '' + prefix
- 15| line += comma + m
- 16| comma = ', '
- 17| if not line.endswith( ' ' ) :
- 18| print line.replace( '|', '>' )
- 19| if type( attr ) == type( '' ) :
- 20| comma, line = '', '' + prefix
- 21| attribs = [
- 22| n for n, v in vars( Class ).items()
- 23| if n.lower().find( attr.lower() ) > -1 and not callable( v )
- 24| ]
- 25| attribs.sort()
- 26| for a in attribs :
- 27| if len( line + comma + a ) > 65 :
- 28| print line.replace( '|', '*' )
- 29| comma, line = '', '' + prefix
- 30| line += comma + a
- 31| comma = ', '
- 32| if not line.endswith( ' ' ) :
- 33| print line.replace( '|', '*' )
- 34| for b in Class.__bases__ :
- 35| classInfo( b, meth, attr, pad + '| ' )
复制代码
|
|