将shebang编译成pyc文件 [英] compile shebang into pyc file

查看:84
本文介绍了将shebang编译成pyc文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


有没有办法把python文件foo.py编译成foo.pyc(或foo.pyo)

这样foo .pyc可以在命令行上使用''foo.pyc''(而不是''python

foo.pyc'')运行吗?


J?rg Schuster

Hello,

is there a way to compile a python file foo.py to foo.pyc (or foo.pyo)
such that foo.pyc can be run with ''foo.pyc'' (as opposed to ''python
foo.pyc'') on the command line?

J?rg Schuster

推荐答案

是否有某些原因要运行.pyc文件,而不是

..py文件?如果你用

#开始编写脚本! / usr / bin / env python


然后,如果文件具有执行权限集,则键入文件名

(foo.py)将生成脚本在它的

上调用Python解释器。

Is there some reason why you want to run the .pyc file, rather than the
..py file? If you start the script with

#! /usr/bin/env python

Then if the file has the execution permission set, typing the file name
(foo.py) will make the script call up the Python interpreter on its
own.


2005年4月26日18:15:51 -0700,乔************** @ gmail.com

< jo ************** @ gmail.com>写道:
On 26 Apr 2005 18:15:51 -0700, jo**************@gmail.com
<jo**************@gmail.com> wrote:
你有什么理由想运行.pyc文件而不是
.py文件吗?如果您使用
Is there some reason why you want to run the .pyc file, rather than the
.py file? If you start the script with

启动脚本

a。它更有效率,因为代码在运行之前不需要编译



b。如果你想运送封闭源怎么办?


Mike


-

Michael P. Soulier< ; ms ****** @ gmail.com>
http://www.digitaltorque .ca
http://opag.ca python -c''导入这个''



a. It''s more efficient, since the code doesn''t need to be compiled
before it''s run.
b. What if you want to ship closed-source?

Mike

--
Michael P. Soulier <ms******@gmail.com>
http://www.digitaltorque.ca
http://opag.ca python -c ''import this''


Michael Soulier写道:
Michael Soulier wrote:
你有什么理由要运行.pyc文件,而不是
.py文件?如果你用
Is there some reason why you want to run the .pyc file, rather than the
.py file? If you start the script with

启动脚本
a。它的效率更高,因为代码在运行之前不需要编译。
b。如果你想发送封闭源怎么办?



a. It''s more efficient, since the code doesn''t need to be compiled
before it''s run.
b. What if you want to ship closed-source?




#!/ usr / bin / env python

导入应用


几乎没有资格称为难以编译或开源


< / F>



#!/usr/bin/env python
import app

hardly qualifies as "hard to compile" or "open source"

</F>


这篇关于将shebang编译成pyc文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆