I'm writing a script that works with certain vocabulary. As a part of it, I want to store the incoming json data of a word in a file. The following code works only for one word at a time. But it will replace the data.json
file every time with the json information of the new word.
with open('data.json', 'w') as outfile:
json.dump(data, outfile)
What I'm trying to achieve is: I would like to store the json of each file separately.
For eg: if the word is "internet", then I want the file to export internet.json
and if the word is "persistence," then i want the json to store persistence.json
I tried the below, but it throws a syntax error:.
with open(word||'.json', 'w') as outfile:
json.dump(data, outfile)
I'm new to Python (using Python3) and I'm working on a pet-project. So, it would be a great support if you can help me in achieving this. Thanks in advance.