executing python code

Thorsten Kampe thorsten at thorstenkampe.de
Sat Nov 6 06:34:05 EST 2004


* Darren Dale (2004-11-05 23:47 +0200)
> Some time ago I asked about executing a python program or script. For
> windows, I was informed that the .py extension could be added to some list
> of executable extensions, and then I could just type "mycode" instead of
> "python mycode.py". Great advice, worked like a charm.

"PATHEXT"
 
> I recently jumped ship, and have been running Gentoo Linux for about two
> months. Is it possible to get the same behavior on Linux?

No.

> I thought it
> would have something to do with adding the #!/usr/bin/env python line to my
> code, but I'm not sure what this is supposed to do (it didnt work, that
> much I know.)
> 
> Could I get some advice?

You're confusing a lot of things. Something like "PATHEXT" doesn't
exist on Linux. So you always have to type the full name of the script
(or use tab completion).

You can type "./myapp.py" if the script has the "she bang" first line
mentioned above and the file is executable.

You can type "myapp.py" if the script has the "she bang" first line
mentioned above and the file is executable and the current directory
is in your path (which it is /not/ the default under Linux - contrary
to Windows - and which is not advised).

You can type myapp.py - even if the script is not executable and not
in your path and doesn't have a "#!" line if you use an advanced shell
like zsh (Z Shell) and add a suffix alias ("alias -s py=python") to
your .zshrc

Just typing "myapp" won't work.

Thorsten



More information about the Python-list mailing list