https://github.com/404notf0und/python-guide
Practice makes perfect
https://github.com/404notf0und/python-guide
bugs coding python security tricks
Last synced: about 1 year ago
JSON representation
Practice makes perfect
- Host: GitHub
- URL: https://github.com/404notf0und/python-guide
- Owner: 404notf0und
- Created: 2020-04-26T14:32:19.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-09T16:10:41.000Z (about 6 years ago)
- Last Synced: 2025-03-26T00:51:22.012Z (over 1 year ago)
- Topics: bugs, coding, python, security, tricks
- Language: Python
- Size: 1.15 MB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Python代码规范 by 404notfound
通过不断学习和模仿优秀项目的代码,提升编码能力和风格
## Python编码风格
- 代码注释
- 异常处理
## Python常用语法
- 编码
- str(unicode) vs bytes(gbk,utf-8,gb2312) unicode是转码枢纽
- 迭代器
- next() 小心越界
- 生成器
- yield 函数生成器
- 装饰器的使用
- collections
- OrderedDict有序字典
- SQLite3增删改查
- replace vs update replace:在主键等唯一性约束条件存在时替换
- insert or ignore into
- execute vs executemany
- 时间日期操作datetime
- 目录操作os.path
- glob查找符合特定规则的文件名
- beautifulsoup网页解析库
- .strings .stripped_strings(generator)
- re正则匹配库
- requests HTTP请求库
- 获取重定向url
- shutil文件操作模块,是对os的补充
## Python实现功能
- 全自动化:爬取、分析作图、生成报告、上传github
## 小坑
- requests
- content(byte) vs text(string)
- 读写文件的对象需和文件打开模式保持一致:byte和string 对应'wb'和'w'
## Bugs
1. sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are 2 supplied
- 参数没绑定好,检查sql语句、参数值、参数类型
2. error:ValueError('parameters are of unsupported type')
- 参数类型有误,execute和executemany绑定的参数类型应为list或tuple
3. 使用迭代器next()时,RuntimeError: generator raised StopIteration
- 多次next()导致数据越界
## 小技巧
- str() vs repr()
- codecs语言编码转换
- format字符串格式化函数
## Github灵活使用
- commiter vs author
- git config --global user.name "xx"
- git config --global user.email "xx#gmail.com"
- git commit --author "xx xx#gmail.com"