-
카테고리
-
세부 분야
데이터 분석
-
해결 여부
미해결
purge를 쓰기만하면 계속 에러나오네요
20.07.14 00:09 작성 조회수 178
0
import sys
import io
from tinydb import TinyDB, Query
from tinydb.storages import MemoryStorage
import simplejson as json
sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding = 'utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding = 'utf-8')
#파일 DB 생성
# db = TinyDB('d:/python/section5/databases/database.db',default_table='todos') #테이블명 지정안하면 default로 생성
db = TinyDB('d:/python/section5/databases/database.db',default_table='users')
#메모리 DB 생성
db = TinyDB(storage=MemoryStorage, default_table='users')
#테이블 선택
users = db.table('users')
#테이블 데이터 전체 삽입1
with open('d:/python/section5/data/users.json','r') as infile:
r = json.loads(infile.read())
for p in r:
users.insert(p)
#전체 데이터 출력
print(users.all())
#테이블 목록 조회
print(db.tables())
#전체 데이터 삭제
users.purge()
# todos.purge()
db.close()
코딩은 제가한 거랑 선생님께서 해주신거 전부다 에러네요
몇번을 아나콘다 아톰 지웠다가 깔았습니다 힘드네요
Traceback (most recent call last): File "D:\python\section5\5-2-1.py", line 26, in <module> users.purge() AttributeError: 'Table' object has no attribute 'purge'
[Finished in 0.115s]
답변을 작성해보세요.
0
좋은사람
지식공유자2020.07.14
안녕하세요.
tinyDB가 버전 업데이트 되서 레퍼런스를 보니
아래와 같네요.
db.truncate() 또는 users.truncate()로 전체 삭제가 가능합니다.
Removing | |
db.remove(query) |
Remove all documents matching the query |
db.truncate() |
Remove all documents |
답변 1