calllib 1.0

Оценок пока нет — будьте первым

Описание

calllib is a Python module that provides 2 functions, call and getargs. They are used to call Python functions whose parameters are not known in advance, but are determined at runtime from a mapping of available objects. This is particularly useful in plug-in frameworks, where you don't want every callback function to be required to have identical signatures. Instead, each function can take a subset of available parameters. For example: from __future__ import print_function from datetime import datetime from calllib import call def callback1(time): print('callback1 called at:', time) def callback2(time, reason): print('callback2 called at:', time, 'reason:', reason) callbacks = [callback1, callback2] args = {'time': datetime.now(), 'reason': 'abort'} for callback in callbacks: call(callback, args) The last line shows that you can call any number of callback routines without knowing their exact arguments, as long as their arguments are a subset of args. Types of callables supported calllib supports any callable written in Python. Because they are not introspectable by the inspect module, built in Python functions such as len() cannot be used with call(). Default arguments Functions with default arguments are fully supported by calllib. Requirements:

Информация о программе

  • Категория: Другое
  • ОС: Linux
  • Скачиваний: 0
Скачать