Calling a python script from command line without typing “python” first

前端 未结 6 622
暖寄归人
暖寄归人 2020-11-29 10:27

Question: In command line, how do I call a python script without having to type python in front of the script\'s name? Is this even possible?


Info

6条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 10:56

    You want a shebang. #!/path/to/python. Put that on the first line of your python script. The #! is actually a magic number that tells the operating system to interpret the file as a script for the program named. You can supply /usr/bin/python or, to be more portable, /usr/bin/env python which calls the /usr/bin/env program and tells it you want the system's installed Python interpreter.

    You'll also have to put your script in your path, unless you're okay with typing ./SQLsap args.

提交回复
热议问题