realpython / realpython/python-guide
Addition of specific example of great code from one of the listed repositories.
还没有人认领这个 Issue。
- 主要语言
- Batchfile
- 星标
- 29.8k
- 派生
- 5.9k
- PR 合并指标
- 30 天内没有已合并 PR
描述
I absolutely love the Reading Code section, and I've been going through some of the repositories and identifying specific examples of why the code is good.
I was hoping to add one such example to the page. Specifically, from howdoi. It's virtually at the top of the codebase and it deals with standardizing the repository for Python 2 and 3.
https://github.com/gleitz/howdoi/blob/master/howdoi/howdoi.py
# Handle imports for Python 2 and 3
if sys.version < '3':
import codecs
from urllib import quote as url_quote
from urllib import getproxies
# Handling Unicode: http://stackoverflow.com/a/6633040/305414
def u(x):
return codecs.unicode_escape_decode(x)[0]
else:
from urllib.request import getproxies
from urllib.parse import quote as url_quote
def u(x):
return x
I think that there are two (and a half) key pedagogical takeaways from this.
The half takeaway is that supporting different versions of Python need not be a grueling task.
The remaining two are -
- Appropriate use of control flow for module imports and function creation
- Standardizing an API so that its source is indistinguishable to the rest of the code and functionality is consistent.
I haven't formally written this up yet, but if you think it would be a useful example, I can do that and submit a pull request.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 Reading Code 部分和链接的 howdoi/howdoi.py 示例开始。起草一份正式说明,解释 issue 中描述的 Python 2/3 import 处理、控制流和一致的 API,然后将其添加到适当的页面中。当示例及其教学要点包含在一个 pull request 中时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100