realpython / realpython/python-guide

Addition of specific example of great code from one of the listed repositories.

未關閉
#995 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 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 -

  1. Appropriate use of control flow for module imports and function creation
  2. 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.

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 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

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。