I don\'t know how to check if a variable is primitive. In Java it\'s like this:
if var.isPrimitive():
Since there are no primitive types in Python, you yourself must define what you consider primitive:
primitive = (int, str, bool, ...)
def is_primitive(thing):
return isinstance(thing, primitive)
But then, do you consider this primitive, too:
class MyStr(str):
...
?
If not, you could do this:
def is_primitive(thing):
return type(thing) in primitive