This question already has answers here:
Undecompilable Python
(2 answers)
Closed 9 years ago.
Can I block others from seeing my code? I'm working on something in Python. As I save it, it's a (.py) and everyone can right-click and see the code. This is unlike C where I generate an .exe that you can't simply (!) read.
You can read the assembly code generated by the process of the compilation in C. The code is not hidden : it's a bit more complex to read, because it is ASM. But it is totally and definitively not hidden :)
Python is made by Open Source community, so the idea is not about hiding your code. If ever you want to make a .exe from a Python code, you can have a try to Py2Exe or Freeze :
http://www.py2exe.org/
http://wiki.python.org/moin/Freeze
Cheers,
K.
Related
This question already has answers here:
How to obfuscate Python code effectively? [duplicate]
(22 answers)
Closed 2 years ago.
I have been distributing my python scripts as Pyinstaller compiled executeables so that people can't steal my code, but I found that there are many tools like this which can easily decompile executeables generated by Pyinstaller. Is there any way to obfuscate this code. I have seen other people asking similar questions, but people just reply convert the code to c or c++ and compile it. This seems like it would work, but I have no idea where to start.
You can check out this How to obfuscate Python code effectively? for details on how to do a simple obfuscation, but the reality is that obfuscation is basically always reversible. Depending on why you are obfuscating your code there may be better ways to go about this.
If it's just to keep people from stealing your source, most people won't even go as far as the decompilation, but the SO answer above should help. Full on obfuscation even in C or C++ has issues, and usually a system exists to decompile all popular obfuscation systems.
This question already has answers here:
How to step through Python code to help debug issues?
(15 answers)
Closed 3 years ago.
I am trying to learn the basics of programming using python, and I am getting to the point where I have to deal with if statements and for loops. The thing is that I am getting a bit confused as to how my code is running. Is there a way to see how my code is being executed line by line; I feel that that would deepen my understanding of why code has to be written a certain way in order for computers to understand what I am trying to accomplish. I dont know if my question makes any sense to you guys, but I hope you can help me. Thanks a lot in advance.
You can use an interactive debugger. Some Python IDEs provide it.
You may want to give VS Code a try. Take a look at the debugger part of the tutorial.
What you are looking for is called a debugger. You can find some online, for example here: https://www.onlinegdb.com/online_python_debugger . Alternatively you can use pdb, the python debugger (the above link is just a friendly wrapper around it), directly from the command line, but if you are new to python and programming I wouldn't recommand it.
Try pdb.
python -m pdb script.py
More information on How to step through Python code to help debug issues?.
pdb documentation here.
This question already has answers here:
How to drop into REPL (Read, Eval, Print, Loop) from Python code
(7 answers)
Closed 6 years ago.
How would you make the IDLE shell, using nothing but Python code? Now, I understand the beggingins, like a simple exec(raw_input('>> ')), but how would you get if and else statments, or for and while loops to work?
while 1==1:
is considered invalid syntax. How would you prevent that?
The suggested thread isn't nearly the same thing, as all of the answers but one answer how to run a python program from a python program. One of the answers points kinda of like what I'm asking, but it would still fail in an if and else statement, or a while or for loop.
The source code for IDLE is in the Python standard library, under the idlelib package. You can look at the source to see how they implement everything.
idlelib is a lot of code, so it might be overwhelming to try to go through it. The code module provides a Python implementation of Python's interactive mode; you could go through the source code for that to get an idea of how you could do things.
This question already has answers here:
How do I protect Python code from being read by users?
(29 answers)
Closed 9 years ago.
I am writing code (Python and wxpython for GUI) which will run on Debian OS on Raspberry PI. I want to protect/hide the source code. Is there any way to do it? Probably py2exe, or converting it to a library or something else?
The compiled code (.pyc files) can be used if you wish for others to be able to execute but not to read or modify the source code (.py, .pyw).
Simply:
run your application
then copy all the relevant .pyc files into another folder and you should be able to
run it all from the new location
So long as all the appropriate modules are still able to be loaded, everything will work. This will require the version of python to be the same (can't run .pyc files from python 2.4 with python 2.7 and vice-versa)
The other thing to know is that strings will be preserved. You should open them up in a good text editor (I use vim) and inspect the content if you are worried about what others can see.
py2exe is of course another example, but you lose the ability to have cross-platform code at that point -- and if your application is for the Raspberry Pi -- that won't work.
Since you provided no other information about how you intend to run the code, it's not clear if the source will be a module or intended to be run directly. You should read this post to learn more.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Why do people write #!/usr/bin/env python on the first line of a Python script?
I am currently teaching myself Python and I have a question about python. In many examples of Python, I've seen the same line of code at the top:
#!/usr/bin/env python
My question is what purpose does the code above serve, and why is it necessary? So far, I've been practicing Python code without this line of code. If someone could explain this to me, it would help a lot. Thanks in advance.
#!/usr/local/bin/env python
You are specifying the location to the python executable in your machine, that the rest of the script needs to be interpreted with.
You are pointing to python is located at /usr/local/bin/python.
Python is not always installed at '/usr/local/bin/python'. You can also call different python versions by #!/path/to/your/python/version.
It is describing the location of the python install that your code should use. See here and here.