Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- class Database:
- def __init__(self, filename):
- self.__lista = []
- self.__filename = filename
- try:
- f = open(self.__filename, "r")
- self.__lista = json.load(f)
- except:
- f = open(self.__filename, "w")
- f.close()
- def add(self, c):
- self.__lista.append(c)
- def save(self):
- with open(self.__filename, 'w') as json_file:
- json.dump(self.__lista, json_file, indent=2)
- ERRORE : raise TypeError(f'Object of type {o.__class__.__name__} '
- TypeError: Object of type Cocktail is not JSON serializable
- (cocktail è un dizionario)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement