Ask coding questions

← Back to all posts
Another DB Question
GorgonsLair (1)

Maybe I'm just really bad at DBs and need to look at more documentation. I'm trying to update the db using the method below. I've also tried the update() function but my key doesn't change. Is there something I am doing wrong?

        db['test'] = {
              'some' : 0,
              'random' : 0,
              'tests' : 0,
              'here' : 0
              }
        print(db["test"])    
        db['test']['some'] = 3
        print(db["test"])  
Answered by Coder100 (17045) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (17045)

That's actually a bug from replit. Sucks right?
What you actually have to do instead is:

        db['test'] = {
              'some' : 0,
              'random' : 0,
              'tests' : 0,
              'here' : 0
              }
        print(db["test"])  
        temp = db['test']
        temp['some'] = 3
        db['test'] = temp
        print(db["test"])  
GorgonsLair (1)

@Coder100 Dang! I was getting annoyed because I felt like I was doing it right. Thank you for the help!

Bookie0 (5976)

To update the key, do it like this:

db["test"] = {}


db["test"] = {
"foo": "bar" # for nested dicts

}

Instead of what you did (db['test']['some'] = 3)