Skip to content
Sign upLog in
← Back to Community

How to make a save file with Python?

Profile icon
CodersXD

I want to know how you can make a save file with Python.
e.g A password that you make and then when you reload the programme, it has it saved.

If you know, can you tell me, it would help

Voters
Profile icon
CodersXD
Comments
hotnewtop
Profile icon
[deleted]

ok.
import sqlite3
conn = sqlite3.connect("File Name")
file = open("File Name",'a')
file.write(password)

Profile icon
CodersXD

@idrgplayer
, can you make an example repl so I can understand fully? thanks.

Profile icon
[deleted]
Profile icon
[deleted]

@idrgplayer
here is an example..

Profile icon
[deleted]

@idrgplayer
when you type in a password it types it in the db
file, if this help please mark it correct :)

Profile icon
[deleted]

@CodersXD
i did.

Profile icon
[deleted]

@idrgplayer
now if you wanna clear I can teach you?

Profile icon
[deleted]

@idrgplayer
if you wanna clear the db file. just do
def clear():
file.truncate(0)
file.close()

Profile icon
CodersXD

@idrgplayer
, I get it, but what if you want what goes in the file to have "" between them?

Profile icon
[deleted]

@idrgplayer
and make sure you dont close the file outside of this function

Profile icon
[deleted]

@CodersXD
oh then just do like file.write(password + "hi")

Profile icon
[deleted]

Please mark correct if it helped you :)

Profile icon
[deleted]

@idrgplayer
it really helps.

Profile icon
CodersXD
Profile icon
[deleted]

@CodersXD
so you want it to create a new line? just do \n

Profile icon
[deleted]

@idrgplayer
remember this only saves it and if you want to encrypt it that would be hard but it can be done.

Profile icon
CodersXD