[Tutor] finalizing code

Walter Prins wprins at gmail.com
Fri Aug 26 01:39:50 CEST 2011


On 25 August 2011 23:54, Bspymaster <bspymaster at gmail.com> wrote:

> How do I make it so that when you open the program, it starts the code (so
> anyone can use it, not just those who have idle and know ow to program
> python)?
>

To add to what Ramit's said:  On Linux/Ubuntu it's customary to add as the
top line of a script file a "shebang" or "hashbang" header (
http://en.wikipedia.org/wiki/Shebang_%28Unix%29), which typically looks like
this for Python scripts:

#!/usr/bin/env python

This then allows the operating system to know which interpreter to use to
run the script (Python in this case), when you directly try to execute the
script.  In order to be able to run the script like any other command on the
operating system, you also need to actually mark the file as executable.
This may be done via the GUI by right clicking and clicing on "Permssions"
or more easily by executing the command:

chmod +x file.py

This tells the system to make the file executable by anyone on the system.

If the current working folder is the location of the script, you dan then
run it by entering:

./file.py

Additionally it's useful to know that under Ubuntu (and likely some other
Linux variants), if you create a folder called "bin" inside the your home
folder and the the script in there, then you can run the script directly
from any location since your home/bin folder will be automatically searched
when you issue commands without specifying their path/location explicitly.

Hope all that makes sense and helps you.

Walter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110826/6c19dabd/attachment.html>


More information about the Tutor mailing list