user6246005
user6246005

Reputation:

Make Python Script Executable and Have Parameter

I made a Python parser for a language I'm making, and I want the script to be executable in the terminal, I've added a shebang, and tried tried the chmod +x in the terminal, but I got an error when I typed it:

   bash: ./source.py: No file or directory

Even though the file exists.
Also, would anyone know how to add parameters/arguments to the command?

Upvotes: 1

Views: 434

Answers (1)

wim
wim

Reputation: 362756

Your shell likely does not know to execute the script as a python script.

Add a shebang line like

#!/usr/bin/env python

as the first line of the file and try again.

To check command line parameters, for simple things you can look in sys.argv. For anything nontrivial, use the argparse module instead.

Upvotes: 1

Related Questions