How do (not) I distribute my Python progz?

Steven D'Aprano steve at REMOVETHIScyber.com.au
Wed Dec 14 06:07:15 EST 2005


On Wed, 14 Dec 2005 11:41:25 +0100, Juergen Kareta wrote:

> Hi Steven,
> 
>> For many purposes, you can just distribute the .pyc compiled byte-code. 
>> That will discourage the casual user from reading the source code, but 
>> of course a serious programmer will be able to disassemble the .pyc code 
>> very easily.
> 
> very easily ?
> 
> I tried it with my own code a year or two ago, and had some problems 
> (sorry don't remember all steps, but I think there was a tool called 
> disassemble ?). As I don't use a repository at the moment, I would need
> it sometimes to disassemble older versions of my exe'd code. Could you 
> please give some hints, how I can get on ?

What makes you think I'm a serious programmer? *wink*

Try this:


py> import dis  # the Python disassembler
py> 
py> def f(x):
...     print x
...     return x+1
...
py> dis.dis(f)
  2           0 LOAD_FAST                0 (x)
              3 PRINT_ITEM
              4 PRINT_NEWLINE
 
  3           5 LOAD_FAST                0 (x)
              8 LOAD_CONST               1 (1)
             11 BINARY_ADD
             12 RETURN_VALUE
             13 LOAD_CONST               0 (None)
             16 RETURN_VALUE


Python's byte-code is not exactly as easy to understand as native Python,
but it is still understandable. And I wonder, is there a program which
will try to generate Python code from the output of the disassembler?


-- 
Steven




More information about the Python-list mailing list