How to run a python program in a shell without typing "python"

I am new to python. I wrote a program that you can execute by typing python Filecount.py ${argument}Why do I see that my teacher can run the program only by typing Filecount.py ${argument}. How to achieve this?

+4
source share
3 answers

Make it executable

chmod +x Filecount.py

and add hashbang to the beginning Filecount.py, which lets os know that you want to use the python interpreter to execute the file.

#!/usr/bin/env python

Then run it like

./Filecount.py args
+8
source

on a Linux-based OS, you should include a line (at the beginning of your script, i.e. the first line), for example:

#!/usr/bin/python

, python . script.

, script (.. ) .

+2

Add a shebang line to the top of the file: http://en.wikipedia.org/wiki/Shebang_(Unix)#Purpose

It will tell the system which executable file will be used when starting your program.

For example, add

#!/usr/bin/env python

as the first line, and then change the file permissions to execute it.

chmod +x Filecount.py

Good luck

+2
source

Source: https://habr.com/ru/post/1533365/


All Articles