Как записать данные в *.json?
required_account_creating = input('Do you want to make an account in this game? (y/n)')
if required_account_creating == 'y':
try:
playername = input('Create a name for your account. Please remember it: ')
start_time = datetime.now()
created_file_name = str(playername + '.json')
# creating user account's file
with open(created_file_name, 'wb') as account:
# Initializing data: (name, statistics, rating)
contents = {'name': playername, 'all_log-ins': 1, 'longest_game': '', 'most_wins': 0, 'most_lost': 0,
'best_game': '', 'worst_game': '', 'rating': 0}
# writing initialized data into file.
try:
json.dump(contents, account, ensure_ascii=False)
except:
print('Some error appeared when writing data into file. Anyway, file will be created.')
account.close()
time.sleep(3)
quit()
Что я делаю не так?