code: def _encode_python_objects(obj):
      """Try to find the datatype which most closely resembles the object's nature.
  
      If on failure, encode as a string. Plain lists are encoded recursively.
      """
      if isinstance(obj, (list, tuple)) and all(
          [not isinstance(item, (list, tuple)) for item in obj]
      ):
          return [_encode_to_cf(item) for item in obj]
      try:
          dump = _encode_object(obj)
      except ValueError:
          decoded = _try_decode_object(obj)
          dump = json.dumps(decoded, cls=AttributeEncoder).strip('"')
      return dump
  
imports: from __future__ import annotations
  import datetime
  import json
  import logging
  from collections import OrderedDict
  import numpy
  import xarray
  from satpy.writers.utils import flatten_dict
label_desc: Use image node_id 4 for calling a global function with example usage: _encode_python_objects(obj) and returns: dump, unknown