我没写错标题,我确实是想说如何编译Python代码。:-)
见下:
$ cat foo.py
print "hello"
$ ls
foo.py
$ python -mpy_compile foo.py
$ ls
foo.py foo.pyc
$ python foo.pyc
hello
或者另一种方式:
sina@ubuntu:~/work$ ls foo/
foo.py
sina@ubuntu:~/work$ python -mcompileall foo/
Listing foo/ ...
Compiling foo/foo.py ...
sina@ubuntu:~/work$ ls foo/
foo.py foo.pyc
foo.pyc 是二进制文件。