Welcome to Python cheatsheet!¶
- Python 基础小抄
- Python 命名规范
- 使用
__future__
向后移植(backport) 特性 - 查看对象属性
- 定义
__doc__
方法 - 检查实例类型
- 检查、获取、赋值属性
- 继承检查
- 查询所有 global 变量
- 检查 callable
- 获取方法名、类名
__new__
&__init__
- 菱形继承问题
- 类呈现方法
- 长字符串分割
- 优雅地 获取列表元素
- 优雅地 获取字典元素
- 优雅地 给列表、字典赋值
- 命名元组(NamedTuple)
__iter__
- 代理迭代器- 像迭代器一样使用生成器
- 仿写列表
- 仿写字典
- 仿写矩阵乘法
- 装饰器
- 带参数的装饰器
- for-else 语句
- try-else 语句
- Lambda 表达式
- 不定参数 - (*args, **kwargs)
type()
声明(创建)class
- Callable 对象
- 上下文管理 -
with
语句 - 使用
@contextmanager
- 用
with
语句打开文件 - Property - 管理属性
- 计算属性(延迟加载) - 使用 property
- 描述器 - 管理属性
@staticmethod
,@classmethod
- 抽象方法 - 元类(Metaclass)
- 常用 Magic 方法
- 分析 csv
- Python unicode 小抄
- Python generator cheatsheet
- Glossary of Generator
- Produce value via generator
- Unpacking Generators
- Implement Iterable object via generator
- Send message to generator
yield from
expression- yield (from) EXPR return RES
- Generate sequences
- What
RES = yield from EXP
actually do? for _ in gen()
simulateyield from
- Check generator type
- Check Generator State
- Simple compiler
- Context manager and generator
- What
@contextmanager
actually doing? - profile code block
yield from
and__iter__
yield from == await
expression- Closure in Python - using generator
- Implement a simple scheduler
- Simple round-robin with blocking
- simple round-robin with blocking and non-blocking
- Asynchronous Generators
- Asynchronous generators can have
try..finally
blocks - send value and throw exception into async generator
- Simple async round-robin
- Async generator get better performance than async iterator
- Asynchronous Comprehensions
- Python Regular Expression cheatsheet
- Python socket cheatsheet
- Get Hostname
- Transform Host & Network Endian
- IP dotted-quad string & byte format convert
- Mac address & byte format convert
- Simple TCP Echo Server
- Simple TCP Echo Server Via SocketServer
- Simple SSL TCP Echo Server
- Simple UDP Echo Server
- Simple UDP Echo Server Via SocketServer
- Simple UDP client - Sender
- Broadcast UDP Packets
- Simple UNIX Domain Socket
- Simple duplex processes communication
- Simple Asynchronous TCP Server - Thread
- Simple Asynchronous TCP Server - select
- High-Level API - selectors
- “socketpair” - Similar to PIPE
- Sniffer IP packets
- Sniffer ARP packet
- Python cryptography cheatsheet
- Python Concurrency Cheatsheet
- Execute a shell command
- Create a thread via “threading”
- Performance Problem - GIL
- Consumer and Producer
- Thread Pool Template
- Using multiprocessing ThreadPool
- Mutex lock
- Deadlock
- Implement “Monitor”
- Control primitive resources
- Ensure tasks has done
- Thread-safe priority queue
- Multiprocessing
- Custom multiprocessing map
- Graceful way to kill all child processes
- Simple round-robin scheduler
- Scheduler with blocking function
- PoolExecutor
- What “with ThreadPoolExecutor” doing?
- Future Object
- Future error handling
- Python SQLAlchemy Cheatsheet
- Set a database URL
- Sqlalchemy Support DBAPI - PEP249
- Transaction and Connect Object
- Metadata - Generating Database Schema
- Inspect - Get Database Information
- Reflection - Loading Table from Existing Database
- Get Table from MetaData
- Create all Tables Store in “MetaData”
- Create Specific Table
- Create table with same columns
- Drop a Table
- Some Table Object Operation
- SQL Expression Language
- insert() - Create an “INSERT” Statement
- select() - Create a “SELECT” Statement
- join() - Joined Two Tables via “JOIN” Statement
- Delete Rows from Table
- Check Table Existing
- Create multiple tables at once
- Create tables with dynamic columns (Table)
- Object Relational add data
- Object Relational update data
- Object Relational delete row
- Object Relational relationship
- Object Relational self association
- Object Relational basic query
- mapper: Map
Table
toclass
- Get table dynamically
- Object Relational join two tables
- join on relationship and group_by count
- Create tables with dynamic columns (ORM)
- Close database connection
- Cannot use the object after close the session
- Python asyncio cheatsheet
- What is @asyncio.coroutine?
- What is a Task?
- What event loop doing? (Without polling)
- What
asyncio.wait
doing? - Future like object
- Future like object
__await__
other task - Patch loop runner
_run_once
- Put blocking task into Executor
- Socket with asyncio
- Event Loop with polling
- Transport and Protocol
- Transport and Protocol with SSL
- What
loop.create_server
do? - Inline callback
- Asynchronous Iterator
- What is asynchronous iterator
- Asynchronous context manager
- What is asynchronous context manager
- What loop.sock_* do?
- Simple asyncio connection pool
- Simple asyncio UDP echo server
- Simple asyncio web server
- Simple HTTPS asyncio web server
- Simple asyncio WSGI web server
- Python test cheatsheet
- A simple Python unittest
- Python unittest setup & teardown hierarchy
- Different module of setUp & tearDown hierarchy
- Run tests via unittest.TextTestRunner
- Test raise exception
- Pass arguments into a TestCase
- Group multiple testcases into a suite
- Group multiple tests from different TestCase
- Skip some tests in the TestCase
- Monolithic Test
- Cross-module variables to Test files
- skip setup & teardown when the test is skipped
- Re-using old test code
- Testing your document is right
- Re-using doctest to unittest
- Customize test report
- Mock - using
@patch
substitute original method - What
with unittest.mock.patch
do? - Mock - substitute
open
- Python C API cheatsheet
- Python Design Pattern in C