Ask coding questions

← Back to all posts
How do i delete all key-value pairs in replDB?
Chiroyce (4)

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]]

Error -
  File "", line 11, in clear_keys
    del db[keys[i]]

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

Answered by MrVoo (96) [earned 5 cycles]
View Answer
MrVoo (96)

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.