.py和.pyc文件有什么区别? [英] What is the difference between .py and .pyc files?

查看:318
本文介绍了.py和.pyc文件有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到运行某些同名的.py文件时会自动生成.pyc文件. .py.pyc文件之间有什么区别?

I have noticed .pyc files spontaneously being generated when some .py file of the same name gets run. What is the difference between .py and .pyc files?

此外,我发现将.pyc文件放在周围很乱.一个应该删除.pyc文件吗?还是有必要和/或有必要陪伴他们?

Also, I find that having .pyc files lying around clutters up space. Should one delete .pyc files? Or is there a benefit and/or necessity to having them around?

更新:这是2个与我的问题有关的已回答问题

UPDATE: Here are 2 answered questions that are related to my question

如果解释了Python,那么什么是.pyc文件?

为什么主要的可运行Python脚本未编译为模块之类的pyc文件?

此问题不是重复

原因1:因为我要问的是这两个文件之间的区别是什么. S.Lott发现的问题名为如果解释了Python,那么什么是.pyc文件?"不问.py和.pyc文件之间有什么区别.它正在询问什么是.pyc文件.

原因2:因为我的第二个问题是应该删除.pyc文件吗?还是有必要和/或有必要陪伴他们?"提供有关.pyc文件以及如何处理它们的更多信息.

Reason 2: Because my secondary questions 'Should one delete .pyc files? Or is there a benefit and/or necessity to having them around?' provide even more information on .pyc files and how one should handle them.

原因3:因为当像我这样的初学者Python程序员想要找出 .py和.pyc文件之间有什么区别?时,他们会毫无疑问地找到答案因为它们将直接针对我的问题.由于问题很明确,这有助于减少搜索时间.

Reason 3: Because when a beginner Python programmer like myself wants to find out What is the difference between .py and .pyc files? , they will have no problem finding out the answer as they will be guided directly to my question. This helps reduce search time since the question is right to the point.

推荐答案

.pyc包含Python源文件的已编译字节码. Python解释程序先加载.pyc文件,然后再加载.py文件,因此,如果存在的话,它无需重新编译Python源代码即可节省一些时间.您可以根据需要除去它们,但是它们不会引起问题,它们并不大,并且可以在运行程序时节省一些时间.

.pyc contain the compiled bytecode of Python source files. The Python interpreter loads .pyc files before .py files, so if they're present, it can save some time by not having to re-compile the Python source code. You can get rid of them if you want, but they don't cause problems, they're not big, and they may save some time when running programs.

这篇关于.py和.pyc文件有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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