Month: August 2017

  • enum — 枚舉型態 — 你所不知道的 Python 標準函式庫用法 07

    enum — 枚舉型態 — 你所不知道的 Python 標準函式庫用法 07

    enum – Support for enumerations An enumeration is a set of symbolic names (members) bound to unique, constant values. Within an enumeration, the members can be compared by identity, and the enumeration itself can be iterated over. 官方介紹文件:8.13. enum — Support for enumerations enum 是 Python 裏用來建立枚舉形態的標準函式庫。enum 算是比較新的標準函式庫,學習 enum 可以讓你輕鬆建立枚舉,改寫以前單獨使用 const variable 的狀況。 01. Quickstart Tutorial 從今天開始,讓我們把這樣枚舉的 Code: #…

  • concurrent.futures —  創立非同步任務 — 你所不知道的 Python 標準函式庫用法 06

    concurrent.futures — 創立非同步任務 — 你所不知道的 Python 標準函式庫用法 06

    concurrent.futures – Launching parallel tasks The concurrent.futures module provides a high-level interface for asynchronously executing callables. 官方介紹文件:17.4. concurrent.futures — Launching parallel tasks concurrent.futures 提供了一組高階 API 給使用者操作非同步執行的任務。透過 ThreadPoolExectuor 執行 thread 層級的非同步任務,或是使用 ProcessPoolExecutor 執行 process 層級的非同步任務。兩者的 API 介面都相同,同樣繼承於 Executor。 01. Quickstart Tutorial 第一個範例的 target function 使用大家最喜歡的遞迴費氏數列: def fib(n): if n < 2: return 1 return fib(n – 1) + fib(n – 2)…