{"id":18688037,"url":"https://github.com/404notf0und/python-guide","last_synced_at":"2025-04-12T05:30:54.092Z","repository":{"id":129493331,"uuid":"259051824","full_name":"404notf0und/Python-Guide","owner":"404notf0und","description":"Practice makes perfect","archived":false,"fork":false,"pushed_at":"2020-05-09T16:10:41.000Z","size":1208,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T00:51:22.012Z","etag":null,"topics":["bugs","coding","python","security","tricks"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/404notf0und.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-26T14:32:19.000Z","updated_at":"2020-05-09T16:10:43.000Z","dependencies_parsed_at":"2023-04-15T12:32:14.583Z","dependency_job_id":null,"html_url":"https://github.com/404notf0und/Python-Guide","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/404notf0und%2FPython-Guide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/404notf0und%2FPython-Guide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/404notf0und%2FPython-Guide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/404notf0und%2FPython-Guide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/404notf0und","download_url":"https://codeload.github.com/404notf0und/Python-Guide/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248523575,"owners_count":21118528,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bugs","coding","python","security","tricks"],"created_at":"2024-11-07T10:35:22.375Z","updated_at":"2025-04-12T05:30:54.061Z","avatar_url":"https://github.com/404notf0und.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python代码规范 by 404notfound\n通过不断学习和模仿优秀项目的代码，提升编码能力和风格\n\n## Python编码风格\n- 代码注释\n- 异常处理\n\n## Python常用语法\n- 编码\n\t- str(unicode) vs bytes(gbk,utf-8,gb2312) unicode是转码枢纽\n- 迭代器\n\t- next() 小心越界\n- 生成器\n\t- yield 函数生成器\n- 装饰器的使用\n- collections\n\t- OrderedDict有序字典\n- SQLite3增删改查\n\t- replace vs update replace:在主键等唯一性约束条件存在时替换\n\t- insert or ignore into\n\t- execute vs executemany\n- 时间日期操作datetime\n- 目录操作os.path\n- glob查找符合特定规则的文件名\n- beautifulsoup网页解析库\n\t- .strings .stripped_strings(generator)\n- re正则匹配库\n- requests HTTP请求库\n\t- 获取重定向url\n- shutil文件操作模块，是对os的补充\n\n## Python实现功能\n- 全自动化：爬取、分析作图、生成报告、上传github\n\n## 小坑\n- requests\n  - content(byte) vs text(string)\n  - 读写文件的对象需和文件打开模式保持一致：byte和string 对应'wb'和'w'\n\n## Bugs\n1. sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are 2 supplied\n\t- 参数没绑定好，检查sql语句、参数值、参数类型\n2. error:ValueError('parameters are of unsupported type')\n\t- 参数类型有误，execute和executemany绑定的参数类型应为list或tuple\n3. 使用迭代器next()时，RuntimeError: generator raised StopIteration\n\t- 多次next()导致数据越界\n\n## 小技巧\n- str() vs repr()\n- codecs语言编码转换\n- format字符串格式化函数\n\n## Github灵活使用\n- commiter vs author\n\t- git config --global user.name \"xx\"\n\t- git config --global user.email \"xx#gmail.com\"\n\t- git commit --author \"xx xx#gmail.com\"\n\t\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F404notf0und%2Fpython-guide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F404notf0und%2Fpython-guide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F404notf0und%2Fpython-guide/lists"}