国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

python callable的理解

瀏覽:155日期:2022-08-18 09:58:03

問題描述

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.3self.nport = nport # north port 8080|8443self.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 是什么意思?

問題解答

回答1:

callable用于檢查對象是否可調用,更簡單一點來說就是判斷是不是方法

回答2:

callable就是'可以被call的對象',可以被調用的對象.包括函數,類,含有__call__方法的對象等.你可以在python repl中敲help(callable)看看,或者查python文檔,一般基本的問題和概念,都能解答了.

回答3:

callable(Object)對象Object是否可被調用

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 平阴县| 霍城县| 衡山县| 呼玛县| 大姚县| 平阴县| 南投市| 中西区| 安乡县| 修水县| 新乡县| 陇南市| 衡南县| 四子王旗| 博乐市| 常州市| 九江市| 盐山县| 葵青区| 鄯善县| 广灵县| 贵南县| 盖州市| 醴陵市| 甘谷县| 改则县| 正阳县| 雷波县| 普定县| 黄浦区| 方山县| 额尔古纳市| 黄梅县| 定州市| 年辖:市辖区| 乌兰察布市| 化州市| 都兰县| 信阳市| 武清区| 南和县|