在 Python 脚本的第一行使用 #!/usr/bin/env 有什么作用

 

#!/usr/bin/env 告诉计算机用什么程序执行该脚本。

001、测试两个程序

复制代码
[root@pc1 test]# ls                  ## 两个测试程序
test2.py  test.py
[root@pc1 test]# cat test.py         ## 程序1
print('hello world')
[root@pc1 test]# cat test2.py        ## 程序2
#!/usr/bin/env python
print('hello world')
[root@pc1 test]# python test.py       ## 运行方式1
hello world
[root@pc1 test]# python test2.py      ## 运行方式1
hello world
[root@pc1 test]# ./test.py            ## 运行方式2
./test.py: line 1: syntax error near unexpected token `'hello world''
./test.py: line 1: `print('hello world')'
[root@pc1 test]# ./test2.py           ## 运行方式2
hello world
[root@pc1 test]# python --version
Python 2.7.5
复制代码

 。

 

来源:

01、https://mp.weixin.qq.com/s?__biz=MzI4NDUzNjk1Nw==&mid=2247487773&idx=1&sn=0cd2fc717ef2ad94d2af9d5b8f2d23d2&chksm=ebf8a80fdc8f21191be195d9844234cafd98cd43437b357d2d2cd00c1dd7bf56cd10705c7db9#rd

 

posted @   小鲨鱼2018  阅读(47)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2022-10-31 >chr1 <_io.TextIOWrapper name='result.fa' mode='w' encoding='UTF-8'>
2022-10-31 python 中实现将两个列表合并为字典
2022-10-31 linux 中实现文本的按列反转
2021-10-31 R语言中矩阵运算
2021-10-31 R语言实现计算两个向量的协方差、标准差、皮尔逊相关系数
2021-10-31 R语言统计 plink格式数据样本缺失率
2021-10-31 linux shell 统计plink格式样本缺失率
点击右上角即可分享
微信分享提示