Excute script only from another file

Rick Johnson rantingrickjohnson at gmail.com
Tue Nov 26 03:28:42 CET 2013

On Monday, November 25, 2013 4:52:46 AM UTC-6, Himanshu Garg wrote:

> My motive is "I will give scripts to somebody else and he
> should not run the script directly without running the 
> parent script".

The only sure fire method to prevent a file containing
Python code from executing on a machine with Python
installed is to use an extension that the system will not
associate with Python.


Of course, any other Python module that needs to leverage
the API contained within the "aliased mod files" will need
to do so *manually*:

 1. Read the file from disc
 2. Evaluate the file contents and make callable
 3. Close the file

Sounds like your distributing a Python application and need
a simplistic method by which "non-techies" can run the code,
but as we all know:

 "fools are too cleaver!"

Of course a smarty pants could could change the extension to 
"py[w]", but that would be violating your interface. :) 

Another choice would be to use a package.


But nothing could stop them from accessing the contents of
the package directory. 

A third alternative would be to install the support modules
in a place that the user would be unlikely to look and then
place a mainscript somewhere that is easily accessible. But
even this method will not prevent the running of py scripts.

Sounds like my first offering is the best. At least with 
that method they would be forced into an explicit act of 
renaming the file before they violate your interface.

More information about the Python-list mailing list