diff --git a/src/caosadvancedtools/table_export.py b/src/caosadvancedtools/table_export.py index 63d16a414fff6d8f5e271a5360aa70881bc815c9..c8768ad900239b7c45f2a9d3b6c6ac8b8d0c4fb6 100644 --- a/src/caosadvancedtools/table_export.py +++ b/src/caosadvancedtools/table_export.py @@ -133,6 +133,7 @@ class BaseTableExporter(object): self._check_sanity_of_export_dict() self.raise_error_if_missing = raise_error_if_missing self.info = {} + self.all_keys = [key for key in self.export_dict] def collect_information(self): """Use the items of `export_dict` to collect the information for the @@ -140,7 +141,8 @@ class BaseTableExporter(object): """ - for e, d in self.export_dict.items(): + for e in self.all_keys: + d = self.export_dict[e] if QUERY in d: # TODO: How do we make this more general? There might # be queries that don't need the record or work with @@ -164,11 +166,11 @@ class BaseTableExporter(object): else: self._append_missing(e, d) elif FIND_FUNCTION in d: - try: - self.info[e] = self._call_find_function(d[FIND_FUNCTION], e); - except Exception as exc: + val = self._call_find_function(d[FIND_FUNCTION], e); + if val is not None: + self.info[e] = val + else: self._append_missing(e, d) - logger.debug(exc) # last resort: check if record has e as property: else: try: @@ -202,10 +204,10 @@ class BaseTableExporter(object): def _call_find_function(self, find_function, e): account_for_self = 0 - if callable(d[FIND_FUNCTION]): - find_fun = d[FIND_FUNCTION] + if callable(find_function): + find_fun = find_function else: - find_fun = getattr(self, d[FIND_FUNCTION]) + find_fun = getattr(self, find_function) account_for_self = 1 sig = signature(find_fun) @@ -254,7 +256,8 @@ class BaseTableExporter(object): if print_header: header = "" - for e, d in self.export_dict.items(): + for e in self.all_keys: + d = self.export_dict[e] if e in self.info: body += str(self.info[e]) + delimiter