cpython

python 3.10

蹲街弑〆低调 提交于 2020-08-04 17:05:20
Guido van Rossum, Pablo Galindo, and Lysandros Nikolaou wrote a new Python parser to excise these warts, and proposed PEP 617 to adopt it in CPython. The new parser is written in a more powerful style called a parsing expression grammar (PEG), so the project is named “PEGEN”. pypy team. https://morepypy.blogspot.com/2020/ https://github.com/vstinner/talks https://github.com/pyhandle/hpy 来源: oschina 链接: https://my.oschina.net/innovation/blog/4318860

Python的解释器和字节码

痞子三分冷 提交于 2020-07-29 11:12:21
首先我们先规定Python解释器指的是 CPython解释器。 1. py文件和pyc文件的区别是什么?为什么Python的解释这两个文件都能运行? CPython虚拟机既可以执行python文件,又可以执行编译过的pyc文件,这是因为CPython里面包含了一个可以编译py文件的编译器,执行py文件时,第一步就是要在cpython内部将py文件翻译成字节码文件即pyc文件。 例如创建hello.py文件 print 1+2+3 使用命令python -m compileall hello.py 编译成 hello.py文件 使用 hexdump hello.pyc 输出 pyc文件 0000000 f303 0a0d 1760 5ec9 0063 0000 0000 0000 0000010 0200 0000 4000 0000 7300 0009 0000 0564 0000020 4700 6448 0003 2853 0006 0000 0169 0000 0000030 6900 0002 0000 0369 0000 4e00 0369 0000 0000040 6900 0006 0000 0028 0000 2800 0000 0000 0000050 0028 0000 2800 0000 0000 0873 0000 6800 0000060 6c65

uwsgi nginx 部署 flask

血红的双手。 提交于 2020-07-28 09:35:25
当前项目目录 . ├── app ├── app.log ├── app.py ├── config.py ├── manager.py ├── Pipfile ├── Pipfile.lock ├── __pycache__ │ ├── app.cpython-36.pyc │ ├── app.cpython-37.pyc │ └── view.cpython-36.pyc ├── uwsgi.ini └── uwsgi.pid app.py: from flask import Flask, request from flask_restful import Resource, Api import logging import json app = Flask(__name__) app.config['JSON_AS_ASCII'] = False handler = logging.FileHandler('app.log', encoding='UTF-8') logging_format = logging.Formatter( '%(asctime)s - %(levelname)s - %(filename)s - %(funcName)s - %(lineno)s - %(message)s') handler.setFormatter(logging

Python探索之旅 | 第一部分第三课:初识Python的解释器

柔情痞子 提交于 2020-07-25 09:26:34
作者 谢恩铭,公众号「程序员联盟」(微信号:coderhub)。 转载请注明出处。 原文: https://www.jianshu.com/p/a34eaffcc420 《Python探索之旅》 全系列 内容简介 前言 Python 的解释器 Python 解释器的种类 做一点数学运算 总结 第一部分第三课预告 1. 前言 上一课是 Python探索之旅 | 第一部分第二课:安装Python和Python的常用开发软件 。 经过第一课的理论概念和第二课的 Python 开发环境安装之后,我们是时候来了解一下 Python 的解释器了。 即使这一课的一些小测试看似没什么了不起的,但你却可以借此对 Python 的语法有一个初步概念。我强烈建议你循序渐进地跟着我们动手练习,尤其是如果 Python 是你的第一门编程语言的话。 和任何编程语言一样,Python 具有清晰的语法:你不能随便向 Python 发送任何信息。我们将看到 Python 可以接收什么,不可以接收什么。 2. Python 的解释器 上一课,我们在最后用 PyCharm 创建了一个 Python 的项目,并且创建了我们的第一个 Python 文件( hello_python.py ),然后用项目配置的 Python 解释器(就是我们安装的 Python 中自带的解释器。例如我们上一课在 Windows 中安装的

第12天:Python 之引用

淺唱寂寞╮ 提交于 2020-07-24 19:36:31
by 轩辕御龙 Python 之引用 1. 引用简介与工具引入 Python 中对于变量的处理与 C 语言有着很大的不同,Python 中的变量具有一个特殊的属性:identity,即“身份标识”。这种特殊的属性也在很多地方被称为“引用”。 为了更加清晰地说明引用相关的问题,我们首先要介绍两个工具:一个Python的内置函数: id() ;一个运算符: is ;同时还要介绍一个 sys 模块内的函数: getrefcount() 。 1.1 内置函数 id() id(object) Return the “identity” of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value. 返回值为传入对象的“标识”。该标识是一个唯一的常数,在传入对象的生命周期内与之一一对应。生命周期没有重合的两个对象可能拥有相同的 id() 返回值。 CPython implementation detail: This is the address of the object in

What makes Python3's print function thread safe?

瘦欲@ 提交于 2020-06-25 11:00:31
问题 I've seen on various mailing lists and forums that people keep mentioning that the print function in Python 3 is thread safe. From my own testing, I see no reason to doubt that. import threading import time import random def worker(letter): print(letter * 50) threads = [threading.Thread(target=worker, args=(let,)) for let in "ABCDEFGHIJ"] for t in threads: t.start() for t in threads: t.join() When I run it with Python 3, even though some of the lines may be out of order, they are still always

Building a Python-C-Extension on Windows with a debug Python installation

为君一笑 提交于 2020-06-12 11:41:28
问题 If I build CPython from source on Windows I encounter problems when I want to pip install a package that contains a C-Extension. It seems like the error happens while linking the libraries. For example when installing cython (but it also crashes with the same error on other C extension packages): LINK : fatal error LNK1104: cannot open file 'python38.lib' error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.23.28105\bin\HostX86\x86\link.exe' failed

In C python, accessing the bytecode evaluation stack

耗尽温柔 提交于 2020-06-08 00:47:19
问题 Given a C Python frame pointer, how do I look at arbitrary evaluation stack entries? (Some specific stack entries can be found via locals() , I'm talking about other stack entries.) I asked a broader question like this a while ago: getting the C python exec argument string or accessing the evaluation stack but here I want to focus on being able to read CPython stack entries at runtime. I'll take a solution that works on CPython 2.7 or any Python later than Python 3.3. However if you have

In C python, accessing the bytecode evaluation stack

牧云@^-^@ 提交于 2020-06-08 00:46:18
问题 Given a C Python frame pointer, how do I look at arbitrary evaluation stack entries? (Some specific stack entries can be found via locals() , I'm talking about other stack entries.) I asked a broader question like this a while ago: getting the C python exec argument string or accessing the evaluation stack but here I want to focus on being able to read CPython stack entries at runtime. I'll take a solution that works on CPython 2.7 or any Python later than Python 3.3. However if you have

How is variable assignment implemented in CPython?

心已入冬 提交于 2020-06-07 04:39:05
问题 I know that variables in Python are really just references/pointers to some underlying object(s). And since they're pointers, I guess they somehow "store" or are otherwise associated with the address of the objects they refer to. Such an "address storage" probably happens at a low level in the CPython implementation. But my knowledge of C isn't good enough to infer this from the source code, nor do I know where in the source to begin looking. So, my question is: In the implementation of