Skip to content
Sign upLog in
← Back to Community

How do i delete all key-value pairs in replDB?

Profile icon
Chiroyce

I'm using Python, and I need to clear the replit database, so i decided to get all the keys and delete them one by one, but i get some error

Code -

def clear_keys(): keys = db.keys() for i in keys: del db[keys[i]] clear_keys()
Error - File "main.py", line 11, in clear_keys del db[keys[i]]

Is there an easier way or am I doing something wrong?

Answered by MrVoo [earned 5 cycles]
View Answer
Voters
Profile icon
Chiroyce
Comments
hotnewtop
Profile icon
MrVoo

Try this, you're thinking too hard:

for i in db.keys(): del db[i] # maybe even this: del db.keys()

Also, the database doesn't work on console based projects for some reason.

Profile icon
Chiroyce

@MrVoo
Thanks! It works!!

Profile icon
QuantumCodes

db.clear() thats it. It deletes all keys at once