Practical example of how to transform a dictionary into a json file.
The filename is updated using a variable contained in "count.py". Each file is added to the "listalogiche.dat" file.
From here we start for artificial intelligence.
The filename is updated using a variable contained in "count.py". Each file is added to the "listalogiche.dat" file.
From here we start for artificial intelligence.
import json
import conteggio
import sys
lista2={}
while True:
v1=input('Parola ')
if v1=='fine':
break
elif v1=='annulla':
sys.exit()
else:
v2=input('comando ')
lista2[v1]=v2
nomefile="comandi"+str(conteggio.conta)+".json"
#save lista2 as .json file
with open(nomefile, "w") as json_file:
json.dump(lista2, json_file)
#aggiornamento dei file di configurazione
f=open("conteggio.py","w")
n=conteggio.conta
n+=1
f.write('conta='+str(n))
f.close()
f=open("listalogiche.dat","a")
f.write(nomefile)
f.close()
Nessun commento:
Posta un commento