Hiding Python Source

Stuart Reynolds S.I.Reynolds at cs.bham.ac.uk
Thu Mar 23 19:39:24 CET 2000


t_e_sanders at my-deja.com wrote:
> 
> Hi. I've been following the various "how do you hide Python source?" threads,
> and was wondering if someone could give me a hand with a related problem. I'd
> like to have my Python program import a module written by an arbitrary
> end-user, without allowing the end user to use his module to display my code.
> 
> Specifically, I have a module "mainmodule.pyc" that imports and executes
> "usermodule.py", (which in turn may import mainmodule to make use of its
> functions.) mainmodule might look something like this:
> 

If you don't want the code to be available outside the module (i.e. you
just run it), you can try something like:


a=123

def b(c, d):
    return c+d

print b(a, 456)

# Delete the things you've finished with
del a
del b

# Add this if you want to try to prevent
# it being imported. Note that sys.exit
# throws an exception, though, which can
# be caught.
sys.exit()



Stuart



More information about the Python-list mailing list