Ask coding questions

← Back to all posts
How to store usernames from python to a text file
FatimaNadeem1 (0)

Hi all,
I'm creating a music quiz game and I'm trying to store the usernames and scores in a text file but it says the usernames isn't defined.
Could you please spot the mistake and let me know how to solve :)
Thanks

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

Using a text-based database is not super secure, nor does it work very well on replit.

Try using replit database, it's much easier to use (you can treat it like a python dictionary), and it works much better as a database.
https://docs.replit.com/hosting/database-faq

FatimaNadeem1 (0)

@Coder100 im new on replit so i have no idea how it works, would it work if i use idle?

Coder100 (18939)

no, its called replit database for a reason unfortunately @FatimaNadeem1

FatimaNadeem1 (0)

@Coder100 Oh, finna watch some videos on it then. Thank you.

Coder100 (18939)

@FatimaNadeem1 uh
unfortunately that's like the only tutorial :(

also np!

CosmicBear (56)

@FatimaNadeem1 If you open a repl, you can click the database icon on the left where it will open the instructions.

FatimaNadeem1 (0)

@CosmicBear Thanks I found it, but how do I use it? Like on which line and how?

CosmicBear (56)

@FatimaNadeem1
Add from replit import db to the top. db["key"] = value to add information. variable = db["key"] to get the information.

FatimaNadeem1 (0)

@CosmicBear what kind of information? The one that will be stored in the text file?

CosmicBear (56)

@FatimaNadeem1 do you know how python dictionaries work?

FatimaNadeem1 (0)

@CosmicBear I'm a new learner T-T, btw i figured out how to add info as an ordered list in a text file. Now the problem is that, if you enter a wrong existing username/password, it would still continue with the quiz.. how do I fix that?

Coder100 (18939)

you can check if it exists in the key @FatimaNadeem1

FatimaNadeem1 (0)

@Coder100 do i have to use replit database? No other ways?

Coder100 (18939)

what do you mean?
you can use other databases like firebase or mongo, but replit database is generally the easiest to set up and use @FatimaNadeem1