Running Python Programs¶
The UNIX Way: Executable Bit,
In UNIX, file extensions have no special meaning
Python programs generally don’t have a
Rather, programs are executable through their mode
$ ls -l hello-unix -rw-r--r-- 1 jfasch jfasch 40 Jan 20 09:06 hello-unix
$ chmod 755 hello-unix $ ls -l hello-unix -rwxr-xr-x 1 jfasch jfasch 40 Jan 20 09:07 hello-unix
The UNIX Way: Hash-Bang (She-Bang)¶
Scripts (Shell, Python, Perl, AWK, …) need an interpreter though
Only ELF programs run directly on the CPU
Interpreter line, Hash-Bang, She-Bang: first line in a script, usually
#!/usr/bin/python ... here goes Python code ...
pythonis Python 2 (on the Raspberry, for example)
In Virtual Environments things are different
Python interpreter is not
pythonis taken from
PATHsetting of the environment
#!/usr/bin/env python ...
The UNIX Way: Running¶
Script is executable
Scripts has She-bang
#!/usr/bin/python print('Hello World')
$PATHenvironment variable to find programs
Current working directory is not usually in
$ ./hello-unix Hello World
The Doze Way: Registry¶
In Doze, file extensions have special meaning
In Doze, there is no executable bit, no mode
.pyfiles are executed by the Python interpreter
Extension not necessary when invoking
How does the system know?
During Python installation, the installer registers the Python program as being responsible for
Somewhere in the Windows registry.
Doze always looks in the current working directory 1
> hello-doze Hello World
Ain’t that a security risk?