code: def setobjattr(obj, key, value):
      
      try:
          setattr(obj, key, int(value))
      except ValueError:
          try:
              setattr(obj, key, float(value))
          except ValueError:
              # string if not number
              try:
                  setattr(obj, key, str(value))
              except UnicodeEncodeError:
                  setattr(obj, key, value)
docs: Sets an object attribute with the correct data type.