.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. Compose 定位是 「定义和运行多个 Docker 容器的应用(Defining and running multi-container Docker applications)」

    Compose 简介 | Docker 从入门到实践 https://vuepress.mirror.docker-practice.com/compose/introduction.html Com ...

  2. URL 重定向机制

    由于存在上述三种 URL 重定向机制,那么在多种方法同时设定的情况下,哪种方法会首先起作用呢?优先级顺序如下: HTTP 协议的重定向机制永远最先触发,即便是在没有传送任何页面--也就没有页面被(客户 ...

  3. java 本地方法(JNI)

    最近搞了一个调用第三方so库做登录认证的任务,以前对JNI没什么概念,最近学习了 <java核心技术> 本地方法 一章,把自己写的一些例子记录一下. 自己C语言真是渣渣,所以所有的例子都在 ...

  4. 同时执行多个$.getJSON() 出现数据混乱的问题的解决

    $.getJSON() $.getJSON( url [, data ] [, success(data, textStatus, jqXHR) ] ) url是必选参数,表示json数据的地址: d ...

  5. fastHttp服务端处理请求的过程

    Github 地址 https://github.com/valyala/fasthttp fastHttp 服务端的处理请求的过程 工作过程 主要代码 设置监听地址 server.go func ( ...

  6. MapReduce编程练习(四),统计多个输入文件学生的平均成绩,

    问题描述: 在输入文件中,有多个,其中每个输入文件代表一个学生的各科成绩,其中每行的数据形式为<科目,成绩>,你需要将每个文件中的每科目的成绩进行统计,然后求平均值. 输入文件格式: 这里 ...

  7. UML——基本结构

    一.宏观导图 学习UML的时候我们首先要把握好她的结构,基本上好料都在里面了.最重要的是构造块的学习. 公共机制:是为了让我们更加清楚的描述UML的各种关系.图.事物等. 规则:和语法的意思差不多,就 ...

  8. Luogu 2017 Autumn Camping 游记

    颓得不行的我到D2才想起来自己可以写一篇low得不能再low的游记,然后就动笔了...... Day0 愉快地看着三联,想着别人放一天我放四天的悠闲生活,内心甚是平静.然而晚上回到家就开始浪了,看完了 ...

  9. hdu1313 Round and Round We Go (大数乘法)

    Problem Description A cyclic number is an integer n digits in length which, when multiplied by any i ...

  10. 被收费绘图工具 PUA 了怎么办?来看看这个老实工具吧

    本文非常适合 Electron 入门选手,墙裂推荐! 本文作者:HelloGitHub-蔡文心 大家好!这里是 HelloGitHub 推出的<讲解开源项目>系列,今天给大家带来的一款基于 ...