python callable的理解
巴扎黑
巴扎黑 2017-04-18 10:28:55
0
3
712
class _IMP(object):
    def __init__(self, host='127.0.0.1', nport=8080, sport=8102):
        ''' 8080 for nosecurity, 8443 for security,
            8102 for nosecurity, 8103 for security
        '''
        self.host = host # host address  127.0.0.1|10.6.18.3
        self.nport = nport # north port  8080|8443
        self.sport = sport # south port  8102|8103

    def update(self, **kwargs):
        for k, v in kwargs.iteritems():
            if hasattr(self, k):
                setattr(self, k, v)

    def as_dict(self):
        return {k: getattr(self, k) for k in dir(self) if not k.startswith('_') and \
                 not callable(getattr(self, k))}
a = _IMP()
In [10]: a.as_dict()
Out[10]: {'host': '127.0.0.2', 'nport': 8080, 'sport': 8102}

as_dict 这里的 callable 是什么意思?

巴扎黑
巴扎黑

reply all(3)
洪涛

callable is used to check whether the object is callable. To put it more simply, it is to determine whether it is a method

Peter_Zhu

A callable is an "object that can be called", an object that can be called. It includes functions, classes, objects with __call__ methods, etc.
You can type help (callable) in the python repl to see it, or check the python documentation , all basic questions and concepts can be answered.

左手右手慢动作

callable(Object) Whether the object Object can be called

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!