ikpdb.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:ikpdb 作者: audaxis 项目源码 文件源码
def object_properties_count(self, o):
        """ returns the number of user browsable properties of an object. """
        o_type = type(o)
        if isinstance(o, (types.DictType, types.ListType, types.TupleType, set,)):
            return len(o)
        elif isinstance(o, (types.NoneType, types.BooleanType, types.FloatType, 
                            types.UnicodeType, types.FloatType, types.IntType, 
                            types.StringType, types.LongType, types.ModuleType, 
                            types.MethodType, types.FunctionType,)):
            return 0
        else:
            # Following lines are used to debug variables members browsing
            # and counting
            # if False and str(o_type) == "<class 'socket._socketobject'>":
            #     print "@378"
            #     print dir(o)
            #     print "hasattr(o, '__dict__')=%s" % hasattr(o,'__dict__')
            #     count = 0
            #     if hasattr(o, '__dict__'):
            #         for m_name, m_value in o.__dict__.iteritems():
            #             if m_name.startswith('__'):
            #                 print "    %s=>False" % (m_name,)
            #                 continue
            #             if type(m_value) in (types.ModuleType, types.MethodType, types.FunctionType,):
            #                 print "    %s=>False" % (m_name,)
            #                 continue
            #             print "    %s=>True" % (m_name,)
            #             count +=1
            #     print "    %s => %s = %s" % (o, count, dir(o),)
            # else:
            if hasattr(o, '__dict__'):
                count = len([m_name for m_name, m_value in o.__dict__.iteritems()
                              if not m_name.startswith('__') 
                                and not type(m_value) in (types.ModuleType, 
                                                          types.MethodType, 
                                                          types.FunctionType,) ])
            else:
                count = 0
            return count
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号