I'm new to python and javascript so I don't know much about their data sharing capabilities. Below is the dictionary (whose data I want to send) in a database file I have called database.py. How can I take this data and send it to my javascript file "Calendar.js" so I can use it in a function later?
agenda = {'id' : num,
'eventName' : eventName,
'eventType' : eventType,
'location' : location,
'date' : date,
'time' : time,
'compName' : compName,
'attire' : attire,
'additional' : additional}
1 Answer 1
As a general rule, consider that JSON (JavaScript Object Notation) is the goto-format if you want to exchange data with javascript.
From Python, you can use the json module to generate such data.
Example:
d = {"name":"interpolator",
"children":[{'name':key,"size":value} for key,value in sample.items()]}
j = json.dumps(d, indent=4)
f = open('sample.json', 'w')
print >> f, j
f.close()
Now, for the actual communication with javascript, you can either write the JSON in a file and process it asynchronously, or use something like protobuf/grpc.