python - Writing to JSON produces TypeError: dump() takes at least 2 arguments (1 given) -


i trying load in json file. update , write back. here attempt @ getting error:

typeerror: dump() takes @ least 2 arguments (1 given)

with open('employees.json') data_file:     employees = json.load(data_file)     data_file.close  employees['employees'].append({     "id": "2",     "name": "rob croft",     "key": "0003837852"})  open('employees.json', 'w') data_file:     json.dump(employees)     data_file.close 

you forgot pass in file object:

json.dump(employees, data_file) 

since using file object context manager with statement, not need manually close file. , using data_file.close entirely redundant since not calling file.close() method.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -