Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are a few different approaches you can take here.</p> <p>Python does in fact offer opportunities for minification in the form of <code>;</code>. A little known and little used (thankfully) syntactical element in python is that multiple expressions can be written on one line if <code>;</code> is used.</p> <p>For instance:</p> <pre><code> if x &gt; y: x += y print y else: y += x print x </code></pre> <p>Could be compressed to:</p> <pre><code> if x&gt;y:x+=y;print y; else:y+=x;print x; </code></pre> <p>There are tons of examples of this, you can also remove comments, and obfuscate simple code further with ternary operators. The <code>;</code> gets rid of a ton of whitespace, but there are lots of smaller optimizations that can be made.</p> <p>For some examples of libraries that do this for you, see <a href="http://mnfy.readthedocs.org/en/latest/#a-note-about-version-numbers-and-python-version-compatibility" rel="nofollow">here</a>, <a href="https://github.com/astrand/pyobfuscate" rel="nofollow">here</a>, or <a href="http://code.activestate.com/recipes/576704-python-code-minifier/" rel="nofollow">here</a>.</p> <p>Keep in mind that none of these are going to completely obfuscate your code to the point that it can't be recovered. Any sufficiently motivated person will be able to reverse-engineer your source code, even if undocumented, from this. </p> <p>This remains true even if you only distribute <code>.pyo</code> or <code>.pyc</code> files. Python bytecode is usually not much smaller than the source code used to generate it, and can for the most part be easily reverse-engineered. Do not make the mistake of thinking that distributing a <code>.pyc</code> will completely secure your source code. </p> <p>EDIT: If you are looking to package these as standalone binary executables, you might want to take a look at <a href="http://cx-freeze.sourceforge.net/" rel="nofollow">cx_Freeze</a>. It could be closer to what you are looking for and much harder if not impossible to reverse-engineer.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload