简体   繁体   中英

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. 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. However, i do not understand where this 'default' and '1' comes from.

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? 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 . In your case it is empty - {} .

In the case of pillar table, number 1 is unique identifier - Element 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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