Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #104952

Re: Obfuscating Python code

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.python
Subject Re: Obfuscating Python code
Date 2016-03-15 19:59 +0100
Organization PointedEars Software (PES)
Message-ID <6849887.F7PvubJjsv@PointedEars.de> (permalink)
References <570f76f8-1e4a-421f-b1ff-4fba72f06a56@googlegroups.com> <mailman.155.1458020722.12893.python-list@python.org>

Show all headers | View raw


Ben Finney wrote:

> Swanand Pashankar <swanand.pashankar@gmail.com> 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.

<https://docs.python.org/3.5/license.html>
<http://www.gnu.org/licenses/license-list.html#Python>

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Is there a way to create a shared object file using PyInstaller? Swanand Pashankar <swanand.pashankar@gmail.com> - 2016-03-14 22:35 -0700
  Obfuscating Python code (was: Is there a way to create a shared object file using PyInstaller?) Ben Finney <ben+python@benfinney.id.au> - 2016-03-15 16:45 +1100
    Re: Obfuscating Python code Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-15 19:59 +0100
      Re: Obfuscating Python code Chris Angelico <rosuav@gmail.com> - 2016-03-16 07:31 +1100
        Re: Obfuscating Python code Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-15 22:51 +0100
          Re: Obfuscating Python code Daniel Wilcox <dmw@yubasolutions.com> - 2016-03-15 23:40 -0700
      Re: Obfuscating Python code Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-03-16 18:04 +1100
        Re: Obfuscating Python code Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-03-16 07:55 -0400

csiph-web