0

I have a question about Python projects. I have many projects structured like this:

Project Folder
| main.py
| resources
| | module1.py
| | module2.py

And I'm using this module1.py and module2.py in my main.py application and it all works perfectly fine. But I don't know how to make these modules unreadable (hide them). When you see an application, it's usually full of files that you can't open and see what they are doing, that's what I need. I don't want people to be able to see what these files are doing.

Edit: I need this because in one of my projects, I have a file of database connection that has to be in another file and I need a way to hide its information.

BokiX
  • 412
  • 2
  • 14
  • What does this database connection file do, exactly? Does it have, like, the password to your database or something? – Matthew Tromp Mar 28 '22 at 21:03
  • @MatthewTromp yes, it has all data that is need for admin to connect to a database. It's used for managment application – BokiX Mar 28 '22 at 21:09
  • 1
    It's a bit unclear what the issue is. A well written library would never hard code credentials in it. Use an environment file or environment variable or some other external configuration. – stdunbar Mar 28 '22 at 21:22
  • 1
    Okay, thanks, I will try that but I would still like to find a way of hiding file data that can still be used. Maybe if I have an encrypted file and I make a temp file when my `main.py` starts running where I will paste my decrypted file that I will use. – BokiX Mar 28 '22 at 21:26

2 Answers2

1

You can't, basically. See these answers:

How to obfuscate Python code effectively?

How do I protect Python code from being read by users?

You can compile to bytecode (see first link for details), which makes docstrings and comments unrecoverable, but it can be undone to recover some variable names and the entire structure of your program. If all you need is to make it "kind of annoying" to reverse engineer your code, this might be good enough

Matthew Tromp
  • 194
  • 2
  • 9
  • 1
    No, I need to hide it's content completely, or just make it really hard to decode or something, check the edit of my post, maybe it describes my problem a little bit better. Btw I need to have access to content of these files from `main.py` because I'm storing classes and methods in it. – BokiX Mar 28 '22 at 20:28
  • @BokiX, so _does_ this answer your question or not? In the comment above you wrote "No", but you _did_ accept this answer. Can you clarify? – wovano Nov 10 '22 at 06:11
-3

Open the properties of the file, click on button Advanced and enable encryption for the file. This should help you

Rami Smat
  • 1
  • 2
  • 1
    I can still open the file and see it's content. It is not what I want. Check the edit of my post, maybe it describes my problem a little bit better. – BokiX Mar 28 '22 at 20:27
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 29 '22 at 12:38
  • 1
    @BokiX, while I assume you meant something different, you did not specify this in your question, so technically this answer is correct (although it probably is a WIndows-only answer). Encryption would prevent others from being able to see your database connection details. However, this won't help if you want to distribute your application, but you didn't mention that in your question. – wovano Nov 10 '22 at 06:14