最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python 動(dòng)態(tài)調(diào)用函數(shù)實(shí)例解析

 更新時(shí)間:2019年10月21日 10:43:07   作者:百變小超  
這篇文章主要介紹了python 動(dòng)態(tài)調(diào)用函數(shù)實(shí)例解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

1. 根據(jù)字符串名稱 動(dòng)態(tài)調(diào)用 python文件內(nèi)的方法eval("function_name")(參數(shù))

2. 根據(jù)字符串 動(dòng)態(tài)調(diào)用類(lèi)中的靜態(tài)方法,getattr(ClassName,"function_name")(參數(shù))

3. apply(functoin_name,parameters) 這個(gè)function_name不是字符串,而是函數(shù)對(duì)象本身;parameters是參數(shù),類(lèi)似(a,b,...)這樣的格式

4. 當(dāng)函數(shù)不確定參數(shù)的數(shù)目時(shí)候,采用 一個(gè) * 或兩個(gè)** 他們的用法是有講究的。

下面的例子是,定義了一個(gè)函數(shù)列表字典,字典中保存有函數(shù)對(duì)象和函數(shù)的參數(shù),可以實(shí)現(xiàn)動(dòng)態(tài)為字典添加執(zhí)行的函數(shù),最后一起執(zhí)行

from collections import OrderedDict
 
class ComponentCheck:
  def __init__(self, data_dir):
    self.data_dir = data_dir
 
    self._extend_function_dic = OrderedDict({})
 
  def add_extend_function(self, function_name, *parameters):
    self._extend_function_dic[function_name] = parameters
 
  def _check_extend_function(self):
    for function_name, parameters in self._extend_function_dic.iteritems():
      if not apply(function_name, parameters):
        return False
    return True
 
class CheckFunctions:
  def __init__(self):
    pass
 
  def tollcost_check(data_path):
    toll_cost_path = os.path.join(data_path, Importer.DT_KOR_TOLL_COST)
    tollcost_component = ComponentCheck(toll_cost_path)
    tollcost_component.add_extend_function(tollcost_component.check_file_pattern_list_match, CheckFunctions.TOLL_COST_FILENAME_PATTERN)
    return tollcost_component
@staticmethod
  def speed_camera_check(data_path):
    speed_camera_path = os.path.join(data_path, Importer.DT_SAFETY_CAMERA)
    speed_camera_component = ComponentCheck(speed_camera_path)
    speed_camera_component.add_extend_function(speed_camera_component.check_not_exist_empty_directory)
    return speed_camera_component

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

栾城县| 栖霞市| 鄱阳县| 武隆县| 琼结县| 广州市| 塘沽区| 资中县| 宁阳县| 青铜峡市| 四子王旗| 赣榆县| 攀枝花市| 齐齐哈尔市| 桃园市| 乐安县| 合山市| 紫阳县| 综艺| 鞍山市| 新乡县| 哈巴河县| 东方市| 团风县| 宝丰县| 洮南市| 扶余县| 迭部县| 来安县| 迁西县| 大渡口区| 许昌市| 海城市| 韩城市| 巴彦淖尔市| 青龙| 仁化县| 阜宁县| 加查县| 新安县| 紫云|