View Single Post
thp's Avatar
Posts: 1,391 | Thanked: 4,272 times | Joined on Sep 2007 @ Vienna, Austria
#12
Originally Posted by hawaii View Post
Doesn't NEED .py as the top line of the script indicates the "interpreter" to use and the shell will pass it accordingly, upon execution.
It's called the shebang line, and it only comes into play when your script file is set executable (chmod +x), and you start it directly (i.e. "./myscript" or "myscript" if it's in your $PATH). If your script is in MyDocs (which is mounted noexec on Maemo 5), you cannot start it this way, so you always have to use the interpreter (which - in case of Python - lies in /usr/bin, and is executable) and pass the script as argument in that case.

You can also have Python scripts without the shebang line and without .py as extension - simply start it by passing it as argument to the Python interpreter ("python myscript"). The shebang line is also helpful for editors to autodetect the file type.
 

The Following User Says Thank You to thp For This Useful Post: