Ask coding questions

← Back to all posts
Can someone help me make my Python Chat safer?
h
JWZ6 (673)

many people think that a txt file is bad, so does anyone have an idea on how to use something else? (idk socket)

Answered by xfinnbar (83) [earned 5 cycles]
View Answer
Comments
hotnewtop
xfinnbar (83)

instead of using a file, use replit db, it's like a dict.

from replit import db - Official way, has a dependency with an old version of Flask. I recommend this if you don't need flask

from replitapi import db - Way I created that behaves exactly the same but doesn't depend on old Flask. You may need to install replitapi via the packages tab.

use the db like this:

db["hello"] = "world"

print(db["hello"]) # world

it auto saves and also is private, so that there is not an everlasting message log that anyone can access.

xfinnbar (83)

@Highwayman Yeah, there is no way to access it as when you edit the repl, you must create a fork, and DB does not transfer when you fork, and you can't access anything that isn't accessible to all users via the repl without editing it

Highwayman (1483)

huh. never thought about it like that. I always assumed someone could just do printenv and then start messing with it. @xfinnbar

Highwayman (1483)

why not make a main flask server for the chat client and hold the chat data as a string instead of a file?

Highwayman (1483)

but then why do you have a flask app repl in you repls? @JWZ6

JWZ6 (673)

@Highwayman im trying in out on a tutorial

Highwayman (1483)

lol. just kinda don't wanna? @JWZ6