当前第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》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python脚本怎么执行