当前第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脚本怎么执行的详细内容,更多文章请关注木庄网络博客!!
返回前面的内容
相关阅读 >>
解析Python实现mq消息队列以及消息队列的优点
怎样操作Python遍历numpy数组
Python matplotlib中文显示参数设置解析_Python
在windows中设置Python环境变量的实例讲解
Python会取代php吗?
Python如何使用pip
Python中如何给图形填充颜色
Python中的控制结构有哪些
Python模块之time模块介绍
Python如何计算n的阶乘
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python脚本怎么执行