简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM