I need to do a class that have a method that writes to a json file. I did something like this:
import json
class NameClass:
def __init__(self, a_list):
self.a_list = a_list
def write_method(self):
with open("file_name_where_to_write", 'w') as data:
json.dumps(self.a_list, data)
o = NameClass(a_list_that_I_have)
o.write_method()
I run this but nothing happens. I am not sure why ? If I google this, it keeps coming up json serialisation. json.dumps() it says to take a list and write it to a file.
This is a second question: Does an abstract class usually have init method ? Abstract classes are only used as an example for children classes, and they not supposed to be instantiated. So, abstract class need or not an init method ? Or if it has an init method, what is it for ?
When a class inherits from a parent class, that class calls it parent class inside its init method with super. But this is not the case if the parent is an abstract class ?
Then if you want future classes to implement not only the methods from abstract classes, but to have some certain variables, how is this done ?
Thanks in advance.