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

前端 未结 1 1913
挽巷
挽巷 2021-01-17 15:17

I am trying to load in a json file. Update it and write it back. Here is my attempt at it but I am getting an error:

TypeError: dump() takes at least

相关标签:
1条回答
  • 2021-01-17 15:51

    You forgot to pass in the file object:

    json.dump(employees, data_file)
    

    Since you are using the file object as a context manager with the with statement, you do not need to manually close the file. And using just data_file.close is entirely redundant since you are not even calling the file.close() method.

    0 讨论(0)
提交回复
热议问题