Ask coding questions

← Back to all posts
Array in repl.it database
h
Kingq23 (38)

I need help in making repl.it's database use a array for saving user data

Answered by Coder100 (18148) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (18148)

You can't just append to an array, you must use something like this:

temp = database['<ARRAY>']
temp.append(5)
database['<ARRAY>'] = temp
Kingq23 (38)

@C19wintersp
I am confused how can i use with replit database and also thank you

19wintersp (1142)

@qadams2008 You need to replace <ARRAY> with the pair key.

Kingq23 (38)

@19wintersp hopefully my last question but how do I get the pair key

Coder100 (18148)

that's the key you set it to like

from replit import db
db['name'] = 5

@qadams2008
in this case name is that pair key

Kingq23 (38)

@Coder100 last question how would get it from the database

19wintersp (1142)

The Replit Python module will JSON-serialise Python objects automatically, so if you try to use a list as a database value, it should work properly.

Kingq23 (38)

@19wintersp how would I do this please give an example and thank you

19wintersp (1142)

@qadams2008 I didn't see you were appending, see @Coder100's answer.