from tinydbimport Query,TinyDBfilename= "test2.json"db= TinyDB(filename)#약간 connect 같은 느낌db.purge_table('fruits')#'fruits'라는테이블 삭제table= db.table('fruits')#테이블 생성table.insert({'name':'사과','price':5000})table.insert({'name':'바나나','price':7000})table.insert({'name':'망고','price':8000})table.insert({'name':'레몬','price':5500})print(table.all())item= Query()res= table.search(item.name=='사과')#조건 문 사용print(res[0]['name'])#반환은 리스트형태라서 res[0]을 붙임res= table.search(item.price >6000)for iin res: print ('-',i['name'],i['price'])출처: http://hoony-gunputer.tistory.com/61?category=735007 [후니의 컴퓨터]
'[ 기타 활동 ] > 파이썬' 카테고리의 다른 글
| python-books (0) | 2019.02.19 |
|---|---|
| CSV 테이터 처리하기 (0) | 2018.07.14 |
| MYSQL사용하기 (0) | 2018.07.13 |
| 스크롤러2 (0) | 2018.06.28 |
| 정규 표현식 (Regular Expression) (0) | 2018.05.16 |