Python3 study notes
- Hello World!
- number game
- string method(built-in)
- sequence method(list,tuple built-in)
- function
- dict
- file
- pickle
- inherit(fish)
- timer
- craw youdao dictionary translation
- proxy ip select
- html -> pdf(xhtml2pdf)
- remove ad text
- 21 point#
- KNN
- description
- array structure
- lambda demo
- class demo
- search_engine demo
- decorator demo
- metaclass demo
- iterator generator demo
- coroutine demo (python3.7+!!!)
- futures demo
- asyncio demo
- GIL demo
- gl demo
- context demo
- unit demo
- qt_demo
- qt_crawler
- 一摞Python风格的纸牌
- 如何使用特殊方法
- 特殊方法一览
- 为什么len不是普通方法
- 本章小结
- 延伸阅读
- 内置序列类型概览
- 列表推导和生成器表达式
- 元组不仅仅是不可变的列表
- 切片
- 对序列使用+和*
- 序列的增量赋值
- list.sort方法和内置函数sorted
- 用bisect来管理已排序的序列
- 当列表不是首选
- 本章小结
- 延伸阅读
- 泛映射类型
- 字典推导
- 常见映射类型方法
- 映射的弹性键查询
- 字典的变种
- 子类化UserDict
- 不可变映射类型
- 集合论
- dict和set的背后
- 本章小结
- 延伸阅读
- 字符问题
- 字节概要
- 基本的编解码器
- 了解编解码问题
- 处理文本文件
- 为了正确比较而规范化Unicode字符串
- Unicode文本排序
- Unicode数据库
- 支持字符串和字节序列的双模式API
- 本章小结
- 延伸阅读
- 把函数视为对象
- 高阶函数
- 匿名函数
- 可调用对象
- 用户定义的可调用类型
- 函数内省
- 从定位参数到仅限关键字参数
- 获取关于参数的信息
- 函数注解
- 本章小结
- 延伸阅读
- 案例分析:重构“策略”模式
- “命令”模式
- 本章小结
- 延伸阅读
- 装饰器基础知识
- Python何时执行装饰器
- 使用装饰器改进“策略”模式
- 变量作用域规则
- 闭包
- nonlocal声明
- 实现一个简单的装饰器
- 标准库中的装饰器
- 叠放装饰器
- 参数化装饰器
- 本章小结
- 延伸阅读
- 变量不是盒子
- 标识、相等性和别名
- 默认做浅复制
- 函数的参数作为引用时
- del和垃圾回收
- 弱引用
- Python对不可变类型施加的把戏
- 本章小结
- 延伸阅读
- 对象表示形式
- 再谈向量类
- 备选构造方法
- classmethod与staticmethod
- 格式化显示
- 可散列的Vector2d
- Python的私有属性和“受保护的”属性
- 使用 slots 类属性节省空间
- 覆盖类属性
- 本章小结
- 延伸阅读
- Vector类:用户定义的序列类型
- Vector类第1版:与Vector2d类兼容
- 协议和鸭子类型
- Vector类第2版:可切片的序列
- Vector类第3版:动态存取属性
- Vector类第4版:散列和快速等值测试
- Vector类第5版:格式化
- 本章小结
- 延伸阅读
- Python文化中的接口和协议
- Python喜欢序列
- 使用猴子补丁在运行时实现协议
- Alex Martelli的水禽
- 定义抽象基类的子类
- 标准库中的抽象基类
- 定义并使用一个抽象基类
- Tombola子类的测试方法
- Python使用register的方式
- 鹅的行为有可能像鸭子
- 本章小结
- 延伸阅读
- 子类化内置类型很麻烦
- 多重继承和方法解析顺序
- 多重继承的真实应用
- 处理多重继承
- 一个现代示例:Django通用视图中的混入
- 本章小结
- 延伸阅读
- 运算符重载基础
- 一元运算符
- 重载向量加法运算符+
- 重载标量乘法运算符*
- 众多比较运算符
- 增量赋值运算符
- 本章小结
- 延伸阅读
- Sentence类第1版:单词序列
- 可迭代的对象与迭代器的对比
- Sentence类第2版:典型的迭代器
- Sentence类第3版:生成器函数
- Sentence类第4版:惰性实现
- Sentence类第5版:生成器表达式
- 何时使用生成器表达式
- 另一个示例:等差数列生成器
- 标准库中的生成器函数
- Python 3.3中新出现的句法:yield from
- 可迭代的归约函数
- 深入分析iter函数
- 案例分析:在数据库转换工具中使用生成器
- 把生成器当成协程
- 本章小结
- 延伸阅读
- 先做这个,再做那个:if语句之外的else块
- 上下文管理器和with块
- contextlib模块中的实用工具
- 使用@contextmanager
- 本章小结
- 延伸阅读
- 生成器如何进化成协程
- 用作协程的生成器的基本行为
- 示例:使用协程计算移动平均值
- 预激协程的装饰器
- 终止协程和异常处理
- 让协程返回值
- 使用yield from
- yield from的意义
- 使用案例:使用协程做离散事件仿真
- 本章小结
- 延伸阅读
- 示例:网络下载的三种风格
- 阻塞型I/O和GIL
- 使用concurrent.futures模块启动进程
- 实验Executor.map方法
- 显示下载进度并处理错误
- 本章小结
- 延伸阅读
- Covering Your A** With Assertions
- Complacent Comma Placement
- Context Managers and the with Statement
- Underscores, Dunders, and More
- A Shocking Truth About String Formatting
- “The Zen of Python” Easter Egg
- Python’s Functions Are First-Class
- Lambdas Are Single-Expression Functions
- The Power of Decorators
- Fun With *args and **kwargs
- Function Argument Unpacking
- Nothing to Return Here
- Object Comparisons: “is” vs “==”
- String Conversion (Every Class Needs a repr)
- Defining Your Own Exception Classes
- Cloning Objects for Fun and Profit
- Abstract Base Classes Keep Inheritance in Check
- What Namedtuples Are Good For
- Class vs Instance Variable Pitfalls
- Instance, Class, and Static Methods Demystified
- Dictionaries, Maps, and Hashtables
- Array Data Structures
- Records, Structs, and Data Transfer Objects
- Sets and Multisets
- Stacks (LIFO)
- Queues (FIFOs)
- Priority Queues
- Writing Pythonic Loops
- Comprehending Comprehensions
- List Slicing Tricks and the Sushi Operator
- Beautiful Iterators
- Generators Are Simplified Iterators
- Generator Expressions
- Iterator Chains
- Dictionary Default Values
- Sorting Dictionaries for Fun and Profit
- Emulating Switch/Case Statements With Dicts
- The Craziest Dict Expression in the West
- So Many Ways to Merge Dictionaries
- Dictionary Pretty-Printing
- Exploring Python Modules and Objects
- Isolating Project Dependencies With Virtualenv
- Peeking Behind the Bytecode Curtain
- 确认自己所用的python版本
- 遵循PEP8风格之南
- 了解bytes,str与unicode的区别
- 用辅助函数来取代复杂的表达式
- 了解切割序列的方法
- 在单次切片操作内,不要同时指定start,end,和stride
- 用列表推导来取代map和filter
- 不要使用含有两个以上表达式的列表推导
- 用生成器表达式来改写数据量较大的列表推导式
- 尽量用enumerate取代range
- 用zip函数同时遍历两个迭代器
- 不要在for和while循环后面写else块
- 合理利用try/except/else/finally结构中的每个代码块
- 尽量用异常来表示特殊情况,而不要返回None
- 了解如何在闭包里使用外围作用域中的变量
- 考虑用生成器来改写直接返回列表的函数
- 在参数上面迭代时,要多加小心
- 用数量可变的位置参数减少视觉杂讯
- 用关键字参数来表达可选的行为
- 用None和文档字符串来描述具体动态默认值的参数
- 用只能以关键字形式指定的参数来确保代码明晰
- 尽量用辅助类来维护程序的状态,而不要用字典和元组
- 简单的接口应该接受函数,而不是类的实例
- 以@classmethod形式的多态去通用地构建对象
- 用super初始化父类
- 只在使用Min-in组件制作工具类时进行多重继承
- 多用public属性,少用private属性
- 继承collection.abc以实现自定义容器类型
- 用纯属性取代get和set方法
- 考虑用@property来代替属性重构
- 用描述符来改写需要复用的@property方法
- 用__getattr__,__getattribute__和__setattr__实现按需生成的属性
- 用元类来验证子类
- 用元类来注册子类
- 用元类来注解类的属性
- 用subprocess模块来管理子进程
- 可以用线程来执行阻塞式I/O,但不要用它做平行计算
- 在线程中使用Lock来防止数据竞争
- 用Queue来协调各线程之间的工作
- 考虑用协程来并发地运行多个函数
- 考虑用concurrent.futures来实现真正的平行计算
- 用functools.wraps定义函数修饰器
- 考虑以contextlib和with语句来改写可复用的try/finally代码
- 用copyreg实现可靠的pickle操作
- 应该用datetime模块来处理本地时间,而不是time模块
- 使用内置算法和数据结构
- 在重视精确度的场合,应该使用decimal
- 学会安装由Python开发者社区所构建的模块
- 为每个函数、类和模块编写文档字符串
- 用包来安排模块,并提供稳固的的API
- 为自编的模块定义根异常,以便将调用者与API相隔离
- 用适当的方式打破循环依赖的关系
- 用虚拟环境隔离项目,并重建其依赖关系
- 考虑用模块级别的代码来配置不同的部署环境
- 通过repr字符串来输出调试信息
- 用unittest来测试全部代码
- 考虑用pdb实现交互调试
- 先分析性能,然后再优化
- 用tracemalloc来掌握内存的使用及泄漏情况
- 两数之和
- 整数反转
- 回文数
- 罗马数字转整数
- 最长公共前缀
- 有效的括号
- 删除排序数组中的重复项
- 移除元素
- 实现 strStr()
- 加一
- 最后一个单词的长度
- x 的平方根
- 二进制求和
- 搜索插入位置
- 只出现一次的数字
- 合并两个有序数组
- 多数元素
- 快乐数
- 旋转数组
- 2的幂
- 各位相加
- 缺失数字
- 3的幂
- Project Layout
- Application Setup(Linux and Mac)
- export FLASK_APP=flaskr
- export FLASK_ENV=development
- flask run
- Define and Access the Database
- flask init-db
- Blueprints and Views
- Templates
- Blog Blueprint
- Make the Project Installable
- venv\Scripts\activate
- pip install -e .
- pip list
- Test Coverage
- coverage run -m pytest
- coverage report
- coverage html
- Deploy to Production
- pip install wheel
- python setup.py bdist_wheel
- pip install flaskr-1.0.0-py3-none-any.whl
- export FLASK_APP=flaskr
- flask init-db
- Keep Developing!
- Templates
- Testing Flask Applications
- pip install pytest
- Application Errors
- Debugging Application Errors
- Quickstart
- Request Parsing(marshmallow: deserializing objects(loading))
- Output Fields(marshmallow: serializing objects(dumping))
- Extending Flask-RESTful
- Intermediate Usage
- Quickstart
- nesting schemas
- extending schemas
- examples
- Quickstart
- Introduction into Contexts(init_app)
- Configuration(SQLAlchemy configuration)
- Declaring Models
- Select, Insert, Delete
- Multiple Databases with Binds(SQLALCHEMY_BINDS, bind, bind_key)
- Signalling Support
- Customizing
- Model Class(db = SQLAlchemy(model_class=IdModel))
- Model Mixins(class Post(TimestampMixin, db.Model))
- Query Class(db = SQLAlchemy(query_class=GetOrQuery))
- Model Metaclass(db = SQLAlchemy(model_class=declarative_base(cls=Model, metaclass=CustomMeta, name='Model')))
- Quickstart
- python -m django --version
- django-admin startproject mysite
- python manage.py startapp polls
- python manage.py runserver 0:8000
- python manage.py migrate
- python manage.py makemigrations polls
- python manage.py sqlmigrate polls 0001
- python manage.py createsuperuser
- python manage.py test polls
- 初识Redis
- 使用Redis构建Web应用
- Redis命令
- 数据安全与性能保障
- 使用Redis构建支持程序
- 使用Redis构建应用程序组件
- 基于搜索的应用程序
- 构建简单社交网站
- 降低内存占用
- 扩展Redis
- Redis的Lua脚本编程
- pip freeze > requirements.txt
- pip install -r requirements.txt
- pip install -r requirements.txt -i https://pypi.douban.com/simple/