인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

chokine125888's profile image
chokine125888

asked

Introduction to Python and Creating Various Automated Applications Using Web Crawling

Database Overview

purge를 쓰기만하면 계속 에러나오네요

Written on

·

242

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]
웹-크롤링python

Answer 1

0

niceman님의 프로필 이미지
niceman
Instructor

안녕하세요.

tinyDB가 버전 업데이트 되서 레퍼런스를 보니

아래와 같네요.

db.truncate() 또는 users.truncate()로 전체 삭제가 가능합니다.

Removing
db.remove(query) Remove all documents matching the query
db.truncate() Remove all documents
chokine125888's profile image
chokine125888

asked

Ask a question