Often, when using a Python Package, I find myself using the str()
function to convert a package's custom data-type to a string. If I were to try and create a Python Class for a module, how would I add compatibility to str() function for my package's class?
example:
class Person:
def __init__(self, name, age, likes, dislikes):
self.name = name
self.personality = {
"likes": likes,
"dislikes": dislikes
}
bill = Person("bill", 21, ["coding", "etc"], ["interviews", "socialising"])
strBill = str(bill) # This will store: '<__main__.Person object at 0x7fa68c2acac8>' but I want a dictionary containing all of the variables stored in this 'bill' class
print(strBill)