我正在使用python的mongoDB。我希望用户以JSON格式输入文档,以便我可以将其插入到我的数据库中的某个集合中。如何做到这一点?
答案 0 :(得分:0)
如同类问题所示,Choosing a file in Python with simple Dialog:
from Tkinter import Tk
from tkFileDialog import askopenfilename
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file
print(filename)
答案 1 :(得分:0)
import json
#read string input
dataone= raw_input()
m=json.loads(dataone)
print (m["attribute name in double quotes "])
如果用户输入此字符串{"名称":"乔","年龄":18,"爱好":&# 34;歌唱"} m [" name"]将给出输出joe。