executing a python program by specifying only its name in terminal or command line

Robert Bossy Robert.Bossy at jouy.inra.fr
Tue Feb 26 03:52:25 EST 2008


Steve Holden wrote:
> bharath venkatesh wrote:
>   
>> hi,
>>    i wanna run a python program by specifying  only its  name ex prog 
>> with the arguments in the terminal or command line instead of specifying 
>> python prog in the terminal to run the program   not even specifying the 
>> it with .py extension ..
>> for example i want to run the python program named prog by sepcifying
>> $prog -arguments
>> instead of
>> $python prog -arguments
>> or
>> $prog.py -arguments
>> can anyone tell me how to do it
>>
>>     
> reseach pathext for Windows.
>
> For Unix-like systems use the shebang (#!) line, and don't put a .py at 
> the end of the filename.
Besides being ugly and a bit unsettling for the user, the final .py 
won't prevent the execution of your program.
Though the file must have the executable attribute set, so you have to 
chmod +x it.

Cheers,
RB




More information about the Python-list mailing list