Excute script only from another file

Chris Angelico rosuav at gmail.com
Mon Nov 25 21:41:07 EST 2013


On Tue, Nov 26, 2013 at 1:28 PM, Rick Johnson
<rantingrickjohnson at gmail.com> wrote:
> 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.
>
>  ScriptFolder/
>    script.py
>    mod_1.ignore
>    mod_2.ignore
>    ...

Windows:
C:\Documents and Settings\M>copy con test.ignore
print("Hello, world!")
^Z
        1 file(s) copied.

C:\Documents and Settings\M>python test.ignore
Hello, world!

Linux:
gideon at gideon:~$ cat >test.ignore
print("Hello, world!")
gideon at gideon:~$ python test.ignore
Hello, world!

Totally sure-fire. Absolutely prevents any execution until it's
renamed. By the way, what does "associate" mean, and what does it have
to do with file names?

gideon at gideon:~$ cat >test.ignore
#!/usr/bin/python
print("Hello, world!")
gideon at gideon:~$ chmod +x test.ignore
gideon at gideon:~$ ./test.ignore
Hello, world!

ChrisA



More information about the Python-list mailing list