Running a Python file

Jim Byrnes jf_byrnes at comcast.net
Wed Jul 7 01:59:41 UTC 2010


Cameron Hutchison wrote:
> Jim Byrnes<jf_byrnes at comcast.net>  writes:
>
>> I have been teaching myself Python.  Running some of my programs and
>> others examples I noticed that some I could run by double-clicking them
>> and others I could not.  Looking at the file permissions I saw that they
>> were different.  Then I noticed that all the ones I could not run were
>> ones I gone into Properties-->Permissions and check execute as a
>> program.  Once I unchecked it they worked.
>
>> This seems backwards to me.  Could someone tell me why this works this way?
>
> If your python program is executable, it must have a first line of
> something line this:
> #!/usr/bin/python
>
> or sometimes
>
> #!/usr/bin/env python

I should have read my message over before I sent it, I left out two 
things.  I have the Shebang line the programs are GUI (wxPython)

> If you don't have this line, the kernel will not be able to execute it.
> For more info on this first line, see:
> http://en.wikipedia.org/wiki/Shebang_(Unix)
>
> If you turn off execute permission, I assume that the file manager
> recognises that the file is a python program (with the .py extension)
> and runs the python interpreter for you (from the command line, this
> would look like: "python file.py"). Without the file manager doing
> something like this, the program would not be executable. It is likely
> the same logic used when you double-click an openoffice.org document
> (for example). Openoffice.org is launched with the double-clicked file
> as an argument.
>
This explanation is exactly what I needed to get it straight in my 
head.The file is not executing, something else (the 
interperter/OpenOffice) is executing and using the file.

Thanks for the explanation.

Regards,  Jim






More information about the ubuntu-users mailing list