class DeePredict: def __init__(self, model=None, bridge=None): if model: self._model = model if bridge: self._bridge = bridge def model(self, *args, **kwargs): if self.__getattribute__('_model'): return self._model(*args, **kwargs) else: raise ValueError('缺少模型') def bridge(self, *args, **kwargs): return self._bridge(*args, **kwargs) def predict(self, *args, **kwargs): x = self.model(*args, **kwargs) if self.__getattribute__('_bridge'): y = self.bridge(x) return y else: return x if __name__ == '__main__': def f1(x): return x dp = DeePredict(f1, f1) print(dp.predict([1]))