Reputation: 634
So I've been entering the world of Python just recently, and directed it to quick, personal programs made for myself and professional use for web application design with Django. I've taken a few introductory Python tutorials and most Django tutorials, and have been reading Python documentation whenever possible.
I've recently seen that .pyc files are just bytecode (compiled) .py scripts, and don't make the Python language any faster, only lighter and non-human-readable. However, in a medium-low traffic site (let's say, 95% of web sites), this is negligible in difference from PHP, for example (and I find Python to be thousands of times more productive).
The question is: can you execute Python programs from .pyc files where there is no .py file? If yes, is this also possible in Django? How? Is it a good way to make web apps "almost closed source"?
Upvotes: 1
Views: 144
Reputation: 799082
can you execute Python programs from .pyc files where there is no .py file?
Yes. Simply place the .pyc file wherever the .py file would normally be used (except into your text editor, of course).
If yes, is this also possible in Django? How?
No difference. The interpreter handles the files the same way regardless of what framework is being used.
Is it a good way to make web apps "almost closed source"?
Not really. Decompiling compiled Python bytecode is trivial.
Upvotes: 3
Reputation: 12218
Yes, you can execute pycs w/o the py present. It's a common trick for sites that are compiled by a build process rather than living loose in the file system of the host machine. You can also zip the pycs into archives and put the archive in the interpreter's path to so you can manage a whole cluster of files (and folders and subfolders) in one chunk.
OTOH don't expect much security from this route, it's fairly easy to get at the contents of the pycs with something like Uncompyle
Upvotes: 0