Ask coding questions

← Back to all posts
Urgent please tell :Repl.it db
ROCKINGRAYQUAZA (91)

HI THERE!

How to add multiple values to a single key in repl.it database in python

How to view your repl.it database

In python!

Regard,
Rayquaza

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

3 questions?!?
Ok...

# import db

# multiple values
db["my-val"] = ("list", "so", "cool", "right?!?", "more than one value!")

for key in db:
  print(key, ":", key["db"], ",")
ROCKINGRAYQUAZA (91)

these were added by you but if I want that when my bot is added to a new server the owner provide some channel id how will i store that?
@Coder100

Coder100 (18222)

ok, something like:

{
  [serverId]: {
    'channel': [channel]
  }
   ...
}

@ROCKINGRAYQUAZA

ROCKINGRAYQUAZA (91)

Like you can think of it as a input function into a dict @Coder100

Coder100 (18222)

just treat the database as a magical dict that saves
anything you can do to a dict, you can to our database :D
@ROCKINGRAYQUAZA

ROCKINGRAYQUAZA (91)

Also if we want to make nested keys, like:

db[main-key]  = {[sub-key]="value",...} 
#something like this??
```@Coder100 
Coder100 (18222)

reee didn't I say you can treat it like a dict? @ROCKINGRAYQUAZA

Coder100 (18222)

@ROCKINGRAYQUAZA

db['main-key'] = {
  'sub-key': 'value',
  # ...
}
myxi (0)

@Coder100 how do i get the value of a subkey tho

Coder100 (18222)

there are no subkeys
the db gives you either an array, dict, string, or that sort depending on what you set it to. So then treat that value as that. @myxi

Spacecraft (152)

I don't think this is possible. You can assign one value to one key. But, there's nothing that prevents you from entering multiple entries into one key value, like this:

mykey = value1, value2, value3, value4

You would need to split the value string up by commas after reading it, but it could work for you depending on your specific application.

Coder100 (18222)

actually no, repl.it db automatically turns that into JSON which can then be parsed back into it's original form @Spacecraft

Spacecraft (152)

I use this to view a list of all keys in the database:

keys = db.prefix('')
keyList = list(keys)
Spacecraft (152)

Oh, cool, didn't know that. Thanks for the info. @Coder100

ROCKINGRAYQUAZA (91)

So we meet again bookie0 :) @Bookie0

ROCKINGRAYQUAZA (91)

can you help me with my discord bot? i.e. new functions and stuffs [email protected]

Bookie0 (6299)

i dont know how to make a discord bot, but yea I do know functions and stuff @ROCKINGRAYQUAZA

ROCKINGRAYQUAZA (91)

you can tell if you get any idea for my bot also if you like then join my server I have given you the link!! thanks for your help @Bookie0

Bookie0 (6299)

@ROCKINGRAYQUAZA ok later i will give some suggestions