Python

Python 标签下共有 24 篇文章

Pytest Tips

• bwangel Python pytest

pytest 启动 pdb 调试

  1. 安装 ipython

  2. 在想要打断点的地方, 写入语句 import pdb; pdb.set_trace()

  3. 执行 pytest 测试函数

pytest dir/test_files --pdb --pdbcls=IPython.terminal.debugger:TerminalPdb

Pytest …

利用 Python 处理字符串

• bwangel python shell

/tmp/abc.md 中的内容如下

subject/music
antispam/karazhan

我想输出成

Repo(dir='music', name='subject/music'),
Repo(dir='karazhan', name='antispam/karazhan'),

可以利用 Python 来做解析重组字符串的 …

Python2 的正则在 Mac 和 Linux 上的不同表现

• bwangel Python Unicode re blog

表现

s = u'玛丽黛佳眉笔只-需-18,冲p腹t製o2𝒂I5EfW4xPmTq𝒃o2打🤔开桃o寶'

这个字符串 s 是一段淘口令,核心内容就是 𝒂 和 𝒃 之间的 ID I5EfW4xPmTq, 我们想用一个正则表达式将 ID 捕获出来。

𝒂 和 𝒃 的 unicode 码点不在基本平面内,在1号平面内。Unicode 各个平面的字符范围参考 维基百科

在 MacOS …

Thrift Python Client 解析负数 field id 失败

• bwangel Python Thrift blog

thrift python 的 fastbinary 是什么

thrift 在进行通信的时候,Python client 需要将 idl 中定义的方法参数,结构体序列化成字节流。这是在 thrift 的 Protocol 层实现的。

序列化的方式有多种,JSON, Binary, Compact。

Binary 和 Compact 协议的实现有两种,分别是纯 Python 实现和 C++ 实 …

Python2 使用 Thrift 为什么会出现 EINTR 错误

• bwangel python thrift blog

EINTR 错误是什么

man 7 signal 中写到,

If a signal handler is invoked while a system call or library function call is blocked, then either:

• the call is automatically restarted after the signal handler …

从源码安装 confluent-kafka-python

• bwangel tips kafka python

Python 面试题汇总

Python

Python 面试题集合

Django get_or_create 执行过程

Python Django blog

关于 Django 文档get_or_create的解释

Python Upgrade Importerror

Python ImportError blog
  • 记一次因 Python 升级导致的 ImportError

Python的collections模块小结

Python Python标准库 blog

摘要:

  1. 本文章的目标是逐步总结Python中collection模块的用法,会不定期进行更新。
  2. 目前总结了Counter类的用法

Django的override_settings修饰器浅析

Python Django blog
  1. Django的Settings模块代码说明
  2. Django的override_settings修饰器分析

Django中import_string的实现

Django Python blog

摘要:

  1. importlib.import_module 函数的功能
  2. import_string 函数的实现

简单聊聊Python中的wraps修饰器

Python blog

摘要:

Python 中的wraps修饰器分析

Werkzeug 的 wsgi-app 说明

Python Werkzeug
  1. 简要说明了一下WSGI
  2. 分析了Werkzeug的一个官方例子

说说 Python2 中的字符串编码

Python blog

摘要:

  • Python2 中 Str 和 Unicode 分别存了什么
  • raw_unicode_escape 编码的作用
  • Python2 中的一个经典编码问题

Python2 中 Str 和 Unicode 分别存了什么

在 Python2 中,str 存储的是字节流,unicode 存储的是 Unicode 码点

In [1]: '中'
Out[1]: ' …

Python concurrent.futures 文档翻译

Python 翻译 blog

摘要:

本文主要是对 Python3 标准库 concurrent.futures 文档的翻译

Gevent 的 KeyError

Python Gevent stackoverflow 翻译 blog

摘要:

  1. 本文翻译自 StackOverFlow 上的一篇答案
  2. 本文主要解释了gevent的猴子补丁和一个KeyError之间的关系

Python unittesting: run tests in another module

Python unittest blog

摘要:

记录一次解决问题的过程。

Python字符串Format方法示例

Python 翻译 blog

摘要:

本文翻译自Python3文档6.1.3.2. Format examples 主要讲述了Pythonstr.format()的一些使用方法

Python中的生成器和协程

Python blog

摘要:

今天读了《A Curious Course on Coroutines and Concurrency》的第一部分,以下为我的碎碎念。

  1. 生成器和协程的异同
  2. 协程的一些特性

Python的命名空间解析

Python blog

摘要:

  1. 什么是命名空间
  2. 命名空间有哪些
  3. 变量查找原则
  4. 分析一个UnboundLocalError的例子

PEP 343: Python的with语句

• bwangel Python 翻译 blog

摘要:

  1. Python的with语句用法以及相关的上下文管理协议
  2. 如何自己写一个上下文管理器对象,如何利用contextlib来写一个上下文管理器对象
  3. 原文地址: PEP 343: The ‘with’ statement

Python参数

IntermediatePython Python blog

摘要:

  1. IntermediatePython的学习笔记
  2. Python的三种参数

TDD with python 第六章笔记

Python TDD

摘要:

Python Web开发测试驱动方法第六章的笔记