简体   繁体   English

“默认”来自哪里?

[英]Where does 'default' come from?

i've just started using TinyDB as a way to store my data into an JSON file and this makes it easy for my to search for any content in my file. 我刚刚开始使用TinyDB将数据存储到JSON文件中,这使我可以轻松搜索文件中的任何内容。 So, i've copied and pasted a code from https://pypi.python.org/pypi/tinydb and changed the names accordingly to fit this project i am doing. 所以,我复制并粘贴了https://pypi.python.org/pypi/tinydb中的代码并相应地更改了名称,以适应我正在做的这个项目。 However, i do not understand where this 'default' and '1' comes from. 但是,我不明白这个'默认'和'1'来自哪里。

Also, the codes provided to create a table are all done in command line and none written in python3 so does anyone know which websites provide help on creating tables using TinyDB in Python 3? 另外,创建表的代码都是在命令行中完成的,没有用python3编写,所以有谁知道哪些网站提供了在Python 3中使用TinyDB创建表的帮助? I've searched everywhere. 我到处搜寻。

Can someone enlighten me please. 请有人赐教。

from tinydb import TinyDB, Query

db = TinyDB('/home/pi/Desktop/csv/smartkey1.json')
table = db.table('pillar')
table.insert({'active': True})
table.all()
[{'active': True}]

Output: 输出:

{"_default": {}, "pillar": {"1": {"active": true}}}

The _default is showing you content of deafult table . _default向您展示了deafult table的内容。 In your case it is empty - {} . 在你的情况下它是空的 - {}

In the case of pillar table, number 1 is unique identifier - Element ID . pillar表的情况下,编号1是唯一标识符 - 元素ID

Not sure if I understood your last question correctly, but instead of "inputting lines in command line", save those lines in a file with .py extension and run it with python filename.py from your command line. 不确定我是否正确理解了您的上一个问题,而不是“在命令行中输入行”,将这些行保存在扩展名为.py的文件中,并从命令行使用python filename.py运行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM