Should I put #! (shebang) in Python scripts, and what form should it take?

前端 未结 12 1231
感动是毒
感动是毒 2020-11-22 01:27

Should I put the shebang in my Python scripts? In what form?

#!/usr/bin/env python 

or



        
12条回答
  •  庸人自扰
    2020-11-22 01:46

    The purpose of shebang is for the script to recognize the interpreter type when you want to execute the script from the shell. Mostly, and not always, you execute scripts by supplying the interpreter externally. Example usage: python-x.x script.py

    This will work even if you don't have a shebang declarator.

    Why first one is more "portable" is because, /usr/bin/env contains your PATH declaration which accounts for all the destinations where your system executables reside.

    NOTE: Tornado doesn't strictly use shebangs, and Django strictly doesn't. It varies with how you are executing your application's main function.

    ALSO: It doesn't vary with Python.

提交回复
热议问题