動的解析関数呼び出しのPythonの例

  1. Pythonのファイル(「FUNCTION_NAME」)(パラメータ)内の動的呼び出し方法のeval文字列名

  2. 動的呼び出しストリングクラスの静的メソッド、GETATTR(クラス名、「FUNCTION_NAME」)(パラメータ)

  3. パラメータパラメータの形式で(A、B、...)と同様である;これは、文字列FUNCTION_NAMEではなく、オブジェクト自体の機能(functoin_name、パラメータ)を適用します

  4. とき2つの** *またはその使用方法を使用した回数不確実なパラメータの関数は、豪華です。

次の例では、辞書定義された関数のリストである、辞書は、最後に実行が一緒に行われるパラメータ関数オブジェクトと機能を動的辞書機能に加えてもよい含ま

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

私たちは、高齢者が学習しているかを確認するためにサイトを学ぶのpythonをお勧めします!基本的なPythonスクリプト、爬虫類、ジャンゴ、データマイニング、プログラミング技術から、だけでなく、戦闘にゼロベースのpython小さなパートナーを学ぶすべての愛に与えられたデータ項目を、並べ替え!Pythonのベテランの日には、学習し、細部に注意を払う必要性に、クリックにご参加くださいする方法のいくつかを共有するために、技術のタイミングを説明する必要が学習者の集まりPYTHON

リリース3元の記事 ウォンの賞賛0 ビュー856

おすすめ

転載: blog.csdn.net/haoxun07/article/details/104450716