[[email protected] day1]# vi 1.py
#!/usr/bin/python
print "hello word...."
保存退出
[[email protected] day1]# python 1.py
hello word....
-----------------------------------------------------
字节代码
python 源码文件经编译后生成的扩展名后缀为"pyc" 的文件
[[email protected] day1]# vi 2.py
#!/usr/bin/python
import py_compile
py_compile.compile(‘1.py‘)
保存退出
[[email protected] day1]# python 2.py
[[email protected] day1]# ls
1.py 1.pyc 2.py
[[email protected] day1]# python 1.pyc
hello word....
-------------------------------------------------------
优化代码
经过优化的源代码文件,扩展名后缀为"pyo" (建议使用这个)
[[email protected] day1]# python -O -m py_compile 1.py
[[email protected] day1]# ls
1.py 1.pyc 1.pyo 2.py
[[email protected] day1]# python 1.pyo
hello word....
时间: 2024-08-06 20:08:21