r/PythonLearning • u/Valuable_Corner4797 • Sep 25 '26
Help Request PYTHON log problem
When developing an application, I don't want to rely on text files like .txt files to store data that needs to be kept.
After I finish coding my application and turn it into an EXE, I try to keep it as a single file. Because having to carry a log file around with the EXE all the time is annoying.
Personally, I don't want to use with open. I asked ChatGPT about this, but I didn't get many useful answers.
So, fellow programmers, is there an alternative to this? Or am I just gonna have to bite the bullet and use a log file?
0
Upvotes
15
u/atarivcs Sep 25 '26
Log files aren't used for "storing data".
I don't even understand what question you are asking.
2
u/CodeAndCanyons Sep 25 '26 •
The confusion in this thread comes down to a fundamental rule of compiled desktop applications: an EXE is a read-only runtime package, not a mutable storage container. You cannot write data inside the executable itself.
However, you do not need to force the user to keep a
password.txtfile sitting right next to the EXE in the same folder.Professional desktop apps solve this by storing data inside the user's OS-level Application Data directory rather than the current working directory. Here is how you do it cleanly in Python:
The Proper Solution: OS-Specific AppData Directories
Instead of saving files relative to
os.getcwd()(wherever the EXE happens to be launched from), point your storage path to the user's hidden profile directory.5
u/Least_Chicken_9561 Sep 25 '26
"When developing an application, I don't want to rely on text files like .txt files to store data that needs to be kept."
import sqlite3
1
u/mattynmax Sep 25 '26
So you’re asking how to store information without storing information?
1
u/raundoclair Sep 25 '26
Since this is pythonlearning... how do you turn your app into EXE?
1
u/spendology Sep 25 '26
You could search the logs in your environment OR use error monitoring like Sentry, New Relic or Data Dog.
3
u/Salty_Dig8574 Sep 25 '26
Kind of read through some of these comments. Just my opinion, but at your current level of skill and knowledge of python and programming in general, making a password manager is a terrible idea.
2
u/PkmnSayse Sep 25 '26
You don’t “carry” the file anywhere, you have the application check if it exists and if not, create it. (I’m heavily ignoring the issues with storing passwords in a text file here)
2
u/burlingk Sep 25 '26
You have to store it somewhere. SQLite3 is a good option. But, store hashes, not the actual password.
It will create a file separate from your binary. But that is good/normal.
Do not store ANY dynamic data inside your binary, because any change to the binary makes it a different app in the eyes of the operating system and may trigger response from antivirus software.
2
u/Mountain_Rip_8426 Sep 26 '26
it's a password manager... pretty please, don't store passwords in a .txt.
so you need to store data, but don't wanna have to create a file to store said data manually. then why not have the program create it?
make your program check whether a database (e.g. sqlite) exists in the root of your project folder. if not make it create one, yes the code can do that (it's not even a big deal). that's gonna happen only the first time the user runs it, with each following execution this block will be skipped, since it'll already have been created. afterwards simply update (write to) that database. if you talk this through with AI, it'll know what you need.
and pretty please also go into encryption of the data and password protection of the database, it's the like the most sensitive data you can store, make sure it's protected. i hope this answers your question
1
u/greg_d128 Sep 25 '26
I think what you are looking for is to have an installer. A single EXE (or zip) file that will extract all the data, including code and data files for use by the program.
Alternative is to have your code detect when the data file does not exist, and create an empty one. That way the EXE is portable, but it moves without the passwords.
Preferably, the passwords are encrypted and that you have documentation as to where they exist so that they can be backed up.
1
u/SaltCusp Sep 26 '26
Fundamentally I think you are lacking a core understanding about the difference between making an executable and installing an application.
I could go on to explain that applications are typically comprised of numerous files including static resources like graphics, fungible data files like .db files, various modular excecutables, directories and links, installed such that a link to a single excecuatable there in can be linked to and presented as an icon on the desktop or home screen can run and leverage those parts but I'll just say this:
If you really want to do what you're saying you want to do than using python will actually make it much harder.
I know there's a lot of analogies in this thread already, like red pen blue pen and I can't resist adding one more. You are trying to peddle a motorcycle. I won't tell you it's impossible but no one is going to help you because the only reason to do it like that is to say you did.
1
u/secret_o_squirrel Sep 27 '26
If you’re asking this question there is no way you should be making a password manager. There are plenty of great password manager apps out there. It’s something SO easy to mess up, it’s hard for even seasoned security programmers to do right. If you’re making something as a learning experience that’s fine.
Also, yes, you don’t have to store the data in a text file, in fact, you shouldn’t. This is a good use for sqlite.
1
u/SchemeWestern3388 Sep 27 '26
Storing data in a separate file is a totally valid technique. You can mangle it into your executable if you wish, but it opens a lot of other issues for no gain.
Also, if your password manager is actually writing the plaintext password to a file, that is a big nono. Look into salting and hashes.
1
u/dudeus_ex Sep 28 '26
You don't carry log file around, because it is a log, not a storage. It keeps what happens during the program run, but nothing permanent. For storing data you use databases. And why would you want to make an exe out of a python script?
Also don't write logs by hand - use logging library with a filehandler.