This has been bugging me for a while. I can't find anything online that gives me an answer I am looking for. Hopefully you guys canshed some light on this:
Here is a piece of code:
class MyClass():
def __init__(self):
self.name = ''
self.age = 0
self.gender = ''
me = MyClass()
me.name = "john"
me.age = 23
me.gender = "male"
with open('MyFile', 'w') as f:
dict = vars(me)
for attr in dict:
f.write(att + '\n')
Output:
name
age
gender
How i want the output to be like...
name: john
age: 23
gender: male
the format doesn't matter, but something where I can store an instance of a class in a file to be able to read from again.. Anyone have any ideas?