python脚本怎么执行


当前第2页 返回上一页

1)修改文件,添加 #!/usr/bin/python3

1

2

3

4

[Vicky@localhost code]$ vi hello.py

[Vicky@localhost code]$ cat hello.py

#!/usr/bin/python3

print("Hello World!")

2)修改文件权限,添加可执行权限

1

2

3

[Vicky@localhost code]$ chmod u+x hello.py

[Vicky@localhost code]$ ls -la hello.py

-rwxrw-r--. 1 Vicky Vicky 41 10月 19 15:40 hello.py

3)运行

1

2

[Vicky@localhost code]$ ./hello.py

Hello World!

此种方式执行的时候,一定要在脚本文件中指定解释器,否则无法直接运行脚本文件

1

2

3

4

5

6

7

[Vicky@localhost code]$ cat hello.py

print("Hello World!")

[Vicky@localhost code]$ ls -la hello.py

-rwxrw-r--. 1 Vicky Vicky 22 10月 19 15:40 hello.py

[Vicky@localhost code]$ ./hello.py

./hello.py:行1: 未预期的符号 `"Hello World!"' 附近有语法错误

./hello.py:行1: `print("Hello World!")'

以上就是python脚本怎么执行的详细内容,更多文章请关注木庄网络博客!!

返回前面的内容

相关阅读 >>

如何升级mac中自带的openssl ?(过程总结)

Python怎么判断是否为字符串

交叉验证以及Python代码实现

tensorflow基础(机器学习开源软件库)

Python中变量和数据类型介绍

Python如何利用公式计算π

Python数据分析

安装scrapy教程

什么是Python变量?浅谈Python变量中的变量赋值

Python数据分析要学什么数学

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...