Path: csiph.com!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.python Subject: Re: Obfuscating Python code Date: Tue, 15 Mar 2016 19:59:33 +0100 Organization: PointedEars Software (PES) Lines: 38 Message-ID: <6849887.F7PvubJjsv@PointedEars.de> References: <570f76f8-1e4a-421f-b1ff-4fba72f06a56@googlegroups.com> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1458068376 17864 eJwFwYEBACAEBMCViPcZR8X+I3QHC41LD4RjMJ1Lpc87dOYIs1iFTakIsG7Djql4b7daTz4aqhDL (15 Mar 2016 18:59:36 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Tue, 15 Mar 2016 18:59:36 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwFwYEBwCAIA7CXJpai51CE/09Y4puLFaATPj4yn91dlaFV2ZQBvNotPMjy1WWsJlTSwfijIseG33caP4zzFtk= Cancel-Lock: sha1:JoYNKcngRgKd4eD5lz/5mKmqMjQ= X-NNTP-Posting-Host: eJwNx8EBwCAIA8CVkEDAcUBl/xHa+52DiyeMTvPxMS1BoWS9F9J6ydMKB25gn/qfsq/0lGSCHxSLELs= Xref: csiph.com comp.lang.python:104952 Ben Finney wrote: > Swanand Pashankar writes: >> Embedding a Python file in C code works, but it exposes your Python >> script. Didn't find any free fool-proof way to obfuscate Python code >> either. > > What exactly is it you want to prevent? Why do you think obfuscating the > code will achieve that? On a more constructive note, python(1) (CPython) creates a binary (byte- code) “.pyc” file from “.py” files when it runs them. ISTM that you can then run the “.pyc” file as if it were the “.py” file (if the “.pyc” file is given the executable flag, you can even execute it as a standalone command, but that might only work on my system). So apparently you do not have to distribute the source code of a program written in Python if you do not want to. If you want to distribute the “.pyc” file (perhaps under another name), then the “-O” and “-OO” optimization switches for python(1) could come in handy (see “python --help”). [It is then perhaps not a coincidence that “-O” is documented to change the filename suffix from “.pyc” to “.pyo”; cf. “.so”] (The Python manual should have more on this, I have not checked.) That said, not distributing the source code of a program as well (or at least making it available to users in some way) strikes me as unpythonic since Python is at least Open Source software, and Python 2.0.1, 2.1.1 and newer are GPL-compatible Free Software. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail.