Python script header

后端 未结 6 1900
名媛妹妹
名媛妹妹 2020-12-04 10:54

The typical header should be

#!/usr/bin/env python

But I found below also works when executing the script like $python ./my_script.p

6条回答
  •  既然无缘
    2020-12-04 11:25

    From the manpage for env (GNU coreutils 6.10):

    env - run a program in a modified environment
    

    In theory you could use env to reset the environment (removing many of the existing environment variables) or add additional environment variables in the script header. Practically speaking, the two versions you mentioned are identical. (Though others have mentioned a good point: specifying python through env lets you abstractly specify python without knowing its path.)

提交回复
热议问题