Python 脚本的执行

Posted xbit

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 脚本的执行相关的知识,希望对你有一定的参考价值。

 

源文件如下,文件名test.py:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
print ‘Hello World‘
print ‘你好 世界‘

 

执行方式1:

python test.py

 

执行方式2:

sudo chmod +x test.py
./test.py

 

执行方式3,shell脚本也一样,原理是,环境变量PATH中存放的是目录,这些目录中的文件可以直接执行:

sudo chmod +x test.py
sudo cp test.py /usr/bin/
test.py

 



以上是关于Python 脚本的执行的主要内容,如果未能解决你的问题,请参考以下文章