Help with replit db

I wanna add a prefix to a key
but i dont think i know how:

Repl link:

this i what i did two add a prefix

from replit import db["key"] = "apple"#i added one before the key
db.two["key"] = "orange"#i added two after db

this is the error that followed

1 Like

I think no attributes can be added to the replit database!

do you know how to assign a prefix to a key

That’s the thing, you cant.

oh ok
But then what does it mean by this

Interesting, I’ll investigate!

It’s used to list all keys that start with a prefix, for example:

from replit import db

db["key1"] = "value1"
db["key2"] = "value2"
db["key3"] = "value3"
db["otherKey"] = "otherValue"

matches = db.prefix("key")

for key in matches:
	print(f"{key}: {db[key]}")

This code only outputs the keys that start with the prefix “key”, so it doesn’t output “otherKey”.


that makes sense now

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.