.pyc & Python

Python bytecode / 字节码

Python compiles the .py files and saves it as .pyc files , so it can reference them in subsequent invocations.

The .pyc contain the compiled bytecode of Python source files, which is what the Python interpreter compiles the source to.

This code is then executed by Python's virtual machine . There's no harm in deleting them (.pyc), but they will save compilation time if you're doing lots of processing.

Python会编译.py文件并将其保存为.pyc文件,因此它可以在后续调用中引用它们。

.pyc包含Python源文件的已编译字节码,这是Python解释器将源代码编译到的字节码。

然后,此代码由Python的虚拟机执行。删除它们(.pyc)没有什么害处,但是如果您要进行大量处理,它们将节省编译时间。

test.py

# coding: utf8

__author__ = 'xgqfrms'
__editor__ = 'vscode'
__version__ = '1.0.1'
__copyright__ = """
Copyright (c) 2012-2050, xgqfrms; mailto:xgqfrms@xgqfrms.xyz
""" class Test(object):
def sum(a, b):
return a + b

test.pyc


�*_c�����������@���s2���d��Z��d�Z�d�Z�d�Z�d�e�f�d�������YZ�d�S(���t���xgqfrmst���vscodes���1.0.1s@���
Copyright (c) 2012-2050, xgqfrms; mailto:xgqfrms@xgqfrms.xyz
t���Testc�����������B���s���e��Z�d�����Z�RS(���c���������C���s���|��|�S(���N(����(���t���at���b(����(����s@���/Users/xgqfrms-mbp/Documents/GitHub/Python/spider/spider/test.pyt���sum
���s����(���t���__name__t
���__module__R���(����(����(����s@���/Users/xgqfrms-mbp/Documents/GitHub/Python/spider/spider/test.pyR��� ���s���N(���t
���__author__t
���__editor__t���__version__t
���__copyright__t���objectR���(����(����(����s@���/Users/xgqfrms-mbp/Documents/GitHub/Python/spider/spider/test.pyt���<module>���s���

env

声明为可执行文件, 不会编译成字节码

#! /usr/bin/env python
# 声明为可执行文件 # coding: utf8 __author__ = 'xgqfrms'
__editor__ = 'vscode'
__version__ = '1.0.1'
__copyright__ = """
Copyright (c) 2012-2050, xgqfrms; mailto:xgqfrms@xgqfrms.xyz
"""
class Test(object):
def sum(a, b):
return a + b

refs

http://net-informations.com/python/iq/pyc.htm

https://stackoverflow.com/questions/2998215/if-python-is-interpreted-what-are-pyc-files

https://en.wikipedia.org/wiki/Pyc



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


.pyc & Python的更多相关文章

  1. python如何编译py文件生成pyc、pyo、pyd以及如何和C语言结合使用

    python执行py文件的流程 当我们执行一个py文件的时候,直接python xx.py即可,那么这个流程是怎么样的呢.先说明一下,python执行代码实际上是先打开文件然后执行里面的代码,所以文件 ...

  2. Python Day02

    Python 代码执行流程: 编译 --> 执行 源代码  -->  字节码  -->  机器码  --> CPU执行 python 先将自己的源代码,编译成Python 字节 ...

  3. python环境搭建-Linux系统下python2.6.6升级python3.5.2步骤

    [root@template ~]# python -v # /usr/lib64/python2.6/encodings/utf_8.pyc matches /usr/lib64/python2.6 ...

  4. (Python )模块、包

    本节开始学习模块的相关知识,主要包括模块的编译,模块的搜索路径.包等知识 1.模块 如果我们直接在解释器中编写python,当我们关掉解释器后,再进去.我们之前编写的代码都丢失了.因此,我们需要将我们 ...

  5. 无需操作系统和虚拟机,直接运行Python代码

    Josh Triplett以一个“笑点”开始了他在PyCon 2015上的演讲:移植Python使其无需操作系统运行:他和他的英特尔同事让解释器能够在GRUB引导程序.BIOS或EFI系统上运行.连演 ...

  6. python编译以及反编译

    在Python2.3之前Python自带反编译的工具,高版本的貌似这个反编译的已经不能用了. 据说是在Python2.7上最好用的反编译工具uncompyle 代码地址 http://github.c ...

  7. Python进阶之路---1.4python数据类型-数字

    python入门基础 声明:以后python代码未注明情况下,默认使用python3.x版本 1.python代码基础:print     print('hello,python')   1.1pyt ...

  8. robot framework用python扩展编写自定义library

    我的utils.py文件 #!/usr/bin/env python #-*- coding:utf8 -*- __version__ = '0.1' import sys reload(sys) s ...

  9. Python第一天 安装 shell 文件

    Python第一天  安装  shell  文件 python里面一切都是对象 object 代码缩进:建议用四个空格来缩进,不要用tab键 安装 Linux自带python,windows需要下载m ...

随机推荐

  1. 扩展PE头属性说明

    CRC检测的算法就是checksum 以下是DllCharacteristics的参数说明

  2. 为失败设计,大量引入对SRE的理解,鲁棒性高

    https://go-kratos.dev/#/ Principles 简单:不过度设计,代码平实简单 通用:通用业务开发所需要的基础库的功能 高效:提高业务迭代的效率 稳定:基础库可测试性高,覆盖率 ...

  3. physical CPU vs logical CPU vs Core vs Thread vs Socket(翻译)

    原文地址: http://www.daniloaz.com/en/differences-between-physical-cpu-vs-logical-cpu-vs-core-vs-thread-v ...

  4. Linux常用命令:文件操作命令

    Linux系统命令主要包括文件操作.网络命令和性能命令,本文介绍常用文件操作命令. 修改文件属性 文件类型: 普通文件:- 目录文件:d 块设备文件:b,硬盘 字符设备: c,串行端口的接口设备,例如 ...

  5. MySQL时间格式转换函数

    MySQL DATE_FORMAT() 函数注:当前年份是2018-7-19 SELECT DATE_FORMAT(NOW(),'%Y')                                ...

  6. Spring Boot整合Spring Data JPA

    1.JPA 2.Spring Data JPA 3.导入依赖 4.连接数据库 5.实体类 6.Repository 7.测试 1.JPA JPA是Java Persistence API的简称,中文名 ...

  7. vmware打开虚拟级断电情况下,无法找到虚拟机文件

    1.此时会在建立的虚拟机目录下,有一些 %虚拟机名字%.vmx.lck 或者别的   %虚拟机名字%.***.lck   删除这些文件夹 2.虚拟文件 是一个后缀名为vmx的文件,发现断电后 变成了v ...

  8. Openstack (keystone 身份认证)

    keystone简介 keystone 是OpenStack的组件之一,用于为OpenStack家族中的其它组件成员提供统一的认证服务,包括身份验证.令牌的发放和校验.服务列表.用户权限的定义等等.云 ...

  9. 在VirtualBox上安装Ubuntu-20.04

    本文主要介绍如何在VirtualBox上安装Ubuntu-20.04 目录 下载VirtualBox 下载Ubuntu-20.04镜像 新建虚拟机 第一步:打开VirtualBox 第二步:设置虚拟机 ...

  10. 【uva 10600】ACM Contest and Blackout(图论--次小生成树 模版题)

    题意:有T组数据,N个点,M条边,每条边有一定的花费.问最小生成树和次小生成树的权值. 解法:具体请见 关于生成树的拓展 {附[转]最小瓶颈路与次小生成树}(图论--生成树) 1 #include&l ...