class_docstr: Runs arbitrary function as an interface
  
  Examples
  --------
  
  >>> func = 'def func(arg1, arg2=5): return arg1 + arg2'
  >>> fi = Function(input_names=['arg1', 'arg2'], output_names=['out'])
  >>> fi.inputs.function_str = func
  >>> res = fi.run(arg1=1)
  >>> res.outputs.out
  6
docstr: Parameters
  ----------
  
  input_names: single str or list or None
      names corresponding to function inputs
      if ``None``, derive input names from function argument names
  output_names: single str or list
      names corresponding to function outputs (default: 'out').
      if list of length > 1, has to match the number of outputs
  function : callable
      callable python object. must be able to execute in an
      isolated namespace (possibly in concert with the ``imports``
      parameter)
  imports : list of strings
      list of import statements that allow the function to execute
      in an otherwise empty namespace
docstr_tok: ["Parameters","--","--","--","--","--","input_names",":","single","str","or","list","or","None","names","corresponding","to","function","inputs","if","``","None","``",",","derive","input","names","from","function","argument","names","output_names",":","single","str","or","list","names","corresponding","to","function","outputs","(","default",":","'out","'",")",".","if","list","of","length",">","1",",","has","to","match","the","number","of","outputs","function",":","callable","callable","python","object",".","must","be","able","to","execute","in","an","isolated","namespace","(","possibly","in","concert","with","the","``","imports","``","parameter",")","imports",":","list","of","strings","list","of","import","statements","that","allow","the","function","to","execute","in","an","otherwise","empty","namespace"]
code: def __init__(
      self,
      input_names=None,
      output_names="out",
      function=None,
      imports=None,
      **inputs,
  ):
      """
  
      Parameters
      ----------
  
      input_names: single str or list or None
          names corresponding to function inputs
          if ``None``, derive input names from function argument names
      output_names: single str or list
          names corresponding to function outputs (default: 'out').
          if list of length > 1, has to match the number of outputs
      function : callable
          callable python object. must be able to execute in an
          isolated namespace (possibly in concert with the ``imports``
          parameter)
      imports : list of strings
          list of import statements that allow the function to execute
          in an otherwise empty namespace
      """
  
      super().__init__(**inputs)
      if function:
          if hasattr(function, "__call__"):
              try:
                  self.inputs.function_str = getsource(function)
              except OSError:
                  raise Exception(
                      "Interface Function does not accept "
                      "function objects defined interactively "
                      "in a python session"
                  )
              else:
                  if input_names is None:
                      fninfo = function.__code__
          elif isinstance(function, (str, bytes)):
              self.inputs.function_str = function
              if input_names is None:
                  fninfo = create_function_from_source(
                      function, imports
                  ).__code__
          else:
              raise Exception("Unknown type of function")
          if input_names is None:
              input_names = fninfo.co_varnames[: fninfo.co_argcount]
      self.inputs.on_trait_change(
          self._set_function_string, "function_str"
      )
      self._input_names = ensure_list(input_names)
      self._output_names = ensure_list(output_names)
      add_traits(self.inputs, [name for name in self._input_names])
      self.imports = imports
      self._out = {}
      for name in self._output_names:
          self._out[name] = None
  
file_path: nipype/nipype/interfaces/utility/wrappers.py
imports: from ...None import logging
  from ..base import traits, DynamicTraitedSpec, Undefined, isdefined, BaseInterfaceInputSpec
  from ..io import IOBase, add_traits
  from ...utils.filemanip import ensure_list
  from ...utils.functions import getsource, create_function_from_source
label_desc: Use image node_id 1 to create a new Function object from inherited base classes: IOBase with example: obj = Function(input_names, output_names, function, imports)