Given this simple class:
class Foo(object):
def __init__(self,a=None):
self.a = a
def __repr__(self):
return "Foo(a='{self.a}')".format(self=self)
I'm wondering if there is a simple way to get the __repr__
to return different formatting depending on the type of a:
Foo('some_string') # if a is a string
Foo(5) # if a is the integer 5
Foo(None) # if a is None
Obviously, for a single attribute I could test and have different output strings but I am thinking that someone must have tackled this before me. Specifically, I have several attributes that can be strings or None and I don't see that writing complicated logic for my __repr__
makes much sense.