diff --git a/src/caosadvancedtools/table_export.py b/src/caosadvancedtools/table_export.py index 056207a76fa01357e2269cd4cb8e9a09905d5d90..e6b83be80aedb15cabaa5fde12ac56fce1ca7edd 100644 --- a/src/caosadvancedtools/table_export.py +++ b/src/caosadvancedtools/table_export.py @@ -83,7 +83,7 @@ class BaseTableExporter(object): ``` {"entry_to_be_exported: { "optional": True/False - "find_func": name of member function + "find_func": callable or name of member function "query": query string "selector": selector for the query "error": error explanation @@ -97,8 +97,8 @@ class BaseTableExporter(object): - optional: True or False, if not present, the entry is assumed to be mandatory. - find_func: name of the member function that returns the - value for this entry. Must not exist together with - `query` + value for this entry or callable object. Must not exist + together with `query` - query: Query string for finding the value for this entry. If this is given, a record must be given to the constructor of this class. The query is then executed as @@ -163,7 +163,10 @@ class BaseTableExporter(object): else: self._append_missing(e, d) elif FIND_FUNCTION in d: - find_fun = getattr(self, d[FIND_FUNCTION]) + if callable(d[FIND_FUNCTION]): + find_fun = d[FIND_FUNCTION] + else + find_fun = getattr(self, d[FIND_FUNCTION]) try: self.info[e] = find_fun() except Exception as exc: @@ -287,7 +290,9 @@ class BaseTableExporter(object): # check find function if present if FIND_FUNCTION in d: - if not hasattr(self, d[FIND_FUNCTION]): + if callable(d[FIND_FUNCTION]): + pass + elif not hasattr(self, d[FIND_FUNCTION]): raise TableExportError( "Find function " + d[FIND_FUNCTION] + " was specified for entry " + e +