We can either supply the full path to the file, or use just the file name if we have changed to the directory where the file sits. The output of executing the script will be displayed in the same Terminal window. If the file name argument is omitted, the Python interpreter is run in interactive mode. To exit interactive mode, type control-D.python filename.py
You might think that double-clicking on the t.py icon should execute it. However, what actually happens is that we get a new app t.app) instead. If we now double-click on the t.app icon, something appears briefly in the dock and then disappears. What happened is that the script executed and finished. The output may be found in the system console (which can be examined using Utilities/Console.app). Having to convert a script to an app, execute the app, and then search for the output is not an efficient way of writing and testing programs. Fortunately, there is an easier way. If we do a Get Info on t.py, we see:print "hello world"
To make double-clicking on any Python script behave this way, we can click on the Change All... button in the Open with: section. Of course, we can start a Terminal ourselves and run Python the same way as on Linux (see above). NOTE:The suggestions above are for OS X 10.4. Earlier versions of OS X do not support the Tk user interface library natively, so programs such as "idle" are not available.% "/usr/bin/python" "/Users/conrad/Desktop/t.py" && echo Exit status: $? && exit 1 hello world Exit status: 0 logout [Process exited - exit code 1]
Double-clicking on the t.py icon executes it. Unfortunately, the output appears in a window that immediately disappears. To see the output, we need to start a command window by selecting the Run... item in the Start menu and typing inprint "hello world"
This should pop up a command window. We can then run our program by typing:cmd
We can either supply the full path to the file, or use just the file name if we have changed to the folder where the file sits. The output of executing the script will be displayed in the same command window. If the file name argument is omitted, the Python interpreter is run in interactive mode. To exit interactive mode, type control-Z followed by Enter. To avoid having to type the c:\python24\ part constantly, we can put that folder on our execution path with:c:\python24\python filename.py
Once the Python folder is on our execution path, we can just type:set path=%path%;c:\python24
python filename.py