Skip to content. | Skip to navigation

Personal tools

Navigation

You are here: Home / Tutorial / Python Learning Paths

Python Learning Paths

狹義地說,學習 Python 的核心部份,是指認識它的關鍵字和語法,Python 的關鍵字數量大約40個,一天學三個的話,不超過兩星期就能學完,這部份算是簡單,需要持續精進的部份是,去理解各式資料結構、設計方法、函式庫、開發架構,以便找到適合自己需要的應用方式,或者說,去發掘所謂的最佳實務。

寫程式的目的之一,是為了解決問題,這種情況的成果,通常可視為一種公文;在創造的場合,寫程式才容易開始具備藝術性。

純新手,推薦先閱讀前人的經驗談,看些容易消化的入門影片 #1 #2 Example

學過其他語言的朋友,可以從高處綜觀異同處,例如 C 的語法大量被沿用,許多關鍵字跟 C 是同義,明顯的差別在於 Python 取消括號而採用縮排。Java 比較 Javascript Go + Python

Full Stack Python 指引可能的應用方式

Common Trolls

Michael Driscoll: Python 101 201 wxPython Cookbook

Installation

Portable Python: Python(x,y) WinPython Anaconda manage multiple versions Python Anywhere

for Windows

conda create -n tensorflow python=3.5

source active tensorflow

Basic

IPython Magic Commands Lesser Known Usages Passed by Assignment *args **kwargs formatting: __format__() Essential Python Resources Chrome Extensions IDE Comparison decorator itertools.combinations(mylist, 2)

import sys

def usage():
    print("run_mod.py: a module demo")
    print("option: -v, show version info"

if sys.argv[1] == '-v':
    print("Version 0.1")
else:
    usage()

if __name__ == '__main__':
    print("Main Runs")

sys.path.append('../') 可以 import 相對路徑 但要避免使用 import 陷阱

使用 _ 前置字 (例 safe_format 變成 _safe_format) 的函式模組,可以避免被外部程式呼叫。五種使用 _ 的情況 利用 sys.modules 查詢模組載入狀況

perl equiv: my $result = `grep XXX $filelist`

Learn Python in Y Minutes Python For Beginners

Awesome Python DeadSnakes for Debian

Simple Email Crawler String vs List of Chars Dictionary vs JSON

Python Challenge App Java: Primitive Type

Object vs Type vs Metaclass: 繼承的 class 透過 assert 可以事先檢查

Popularity: Hackathon 除錯時常要理解 Comparison 的細節

The Dynamic Language Runtime and The Iron Languages

person groups was expected to be iterable but was None

-        terms = filter(lambda term: term.value in self.context.groups,
+        terms = filter(lambda term: term.value in (self.context.groups or []),
                        vocabulary)

Private, Protected, Public: Python 並沒有機制阻止變數的存取或物件方法的呼叫,純粹透過社群慣例來處理這類議題,也就是 _ 和 __ 前置字

Name Mangling:

具備 DocString 的函式會成為 Public 除非明確地指定為 Private。

Recursive 範例

Descriptor: @property

Packaging Ecosystem 2016

Intermediate

Binary Search vs Galloping Search

def binary_search(array, target):
    first = 0
    last = len(array) - 1
    comparisons = 0
 
    while first <= last:
        comparisons += 1
        midpoint = (first + last) // 2
        if array[midpoint] == target:
            return (midpoint, comparisons)
        elif array[midpoint] > target:
            last = midpoint - 1
        else:
            first = midpoint + 1
    return (first, comparisons)

def galloping_search(array, target):
 
    if array[0] == target:
        return (0, 1)
    comparisons = 1
 
    # Stage 1 - Find the large index
    size = len(array)
    jump = 1
    cursor = 0
    while cursor < size and array[cursor] < target:
        comparisons += 1
        jump *= 2
        cursor += jump
 
    # Stage 2 - slice the array and run the binary search
    array = array[(cursor // 2):min(cursor, size) + 1]
    sub_search = binary_search(array, target)
 
    return ((cursor // 2) + sub_search[0] - 1, sub_search[1] + comparisons)

Check List Subclass asyncore-file.dispatcher IPython Notebooks ipywidgets jupyter-js-widgets

IPython 字型設定是透過 CSS,檔案預設位於 ~/.ipython/profile_default/static/custom/custom.css,也可以透過 Theme 來設定。

http://try.github.io/

The Data Scientist Skillset

Documentation Contribution Workflow

Egg Introduction

Codio: Django, Pyramid

Plone Document Check List

BananaPi + USB Camera

__future__

Advanced

Namespace by Eric Snow 三種 Namespace Container: mapping-based (VOLATILE) attribute-based (STABLE) property-based (STATIC)

obj[key]            obj.__getitem__(key)
obj[key] = value    obj.__setitem__(key, value)
del obj[key]        obj.__delitem__(key)
key in obj          obj.__contains__(key)

GIL Concurrency Issue: Grumpy Numpy integration

Anti-Patterns Beautiful and Idiomatic

Google Tech Talk 2007:

Everything is Runtime: Compiletime 也是 Runtime,像 .pyc 檔案是 Cached or Borrowed Runtime 預設用來節省時間。

Execution happens in Namespaces: module, function, class 都有自己的 Namespace。

Modules are executed Top-to-Bottom: 就像 Script 方式。載入 Module 後,會從頭到尾執行內容。

def and class statements are Runtime: 執行到的時候,相關的 Function 才建立。一般的 Python 程式碼會被編譯成 Code Object 形式,執行 def 時會把這部份的 Code Object 額外包裝成 Function Object (包含參數)。

def is primarily an assignment statement: 觀察 Bytecode 的話,會發現它跟一般的 assignment 相同。Function 的內容在執行 def 時會被先編譯,但不是馬上被執行,要等到呼叫時才執行。

class statement executes suite (code block) in a separate namespace (a dict): 當 class 執行結束時,會額外建立 Class Object (包含 Namespace 內容),裡面定義的 Function (第一個參數必須是 self) 會變成 Method。

not all callables are functions, even though all functions are callables: range() is not a function call but a call to a type, pow() and sqrt() and like that are true functions, as indicated by feeding them to type().

range() 只能處理整數 numpy.arange() 可以處理浮點數

Modern Dictionary by Raymond Hettinger

How to Write Reusable Code Moving to Python3

The Tao of Python

Concurrent

Python Source Formatter

Big Data XMind

PyCharm The Good Parts Tips Managing Plone Project with PyCharm

List of List: Flat List

res = ['{} . {} = {}'.format(x, y, x * y) for x in range(10) for y in range(10)]

Generator Generator Expression vs List Comprehension Coroutines and Subroutines Tricks for System Programmers

return 代表 function 執行結束,把控制權交回,這種方式通常被稱為 Subroutine。

Class and Object Relation

String Formatting: % vs format

exit vs sys.exit

Desktop Development: #1 #2

Test Driven Development Modules with Different Versions

Stream: Why We Switch from Python to Go

32-bit platform: time.localtime()

Raspberry Pi

Micro SD Card dd on MacOS Tweet from Raspberry Pi with Tweepy Raspberry Pi: Full Stack Chromecast replacer

Excel VBA OpenOffice Calc

Scientific Computing by Fernando Perez

Naming Things: Don't Use Reserved Words

$ python setup.py --classifiers
Framework :: Plone
Framework :: Plone :: 4.3
Programming Language :: Python
Programming Language :: Python :: 2.6
Programming Language :: Python :: 2.7
Topic :: Software Development :: Libraries :: Python Modules

Proxying to a Python Web Application Running in Docker

Super considered super!

Python vs C/C++ in Embedded Systems

Pythonic or Idiomatic Python

一個人必須深刻了解一種語言,才能適當使用成語來表達意思,能善用 Python 成語和禪心,就是 Pythonic

Python3 比 Python2 更容易寫出好品質的程式碼 Python3 Patterns, Recipes, and Idioms 移植範例: zope.app.wsgi

Never Write for loops Again Debugging List Comprehension Design Patterns

Python Worst Practice

Why Ruby Isn't Python

Drew Perttula: I think programmers do not realize which code is an idiom- the C programmer will tell you that she needed to index elements in the list, and wanted the index to start at 0 and run to the end. What's idiomatic about clearly telling the language what you want to do? C programmers probably do realize that x++ or main() {} aren't likely to look the same in python, but I'm not surprised they get mad when there's no switch/case. Python does a lot of work for you, so not only will things not always port directly from unpython to python, but they're often unnecessary once you get here.

def numbers_to_strings(argument):
  switcher = {
    0: "zero",
    1: "one",
    2: "two",
  }
  return switcher.get(argument, "nothing")

Modernised C code: use PyVarObject_HEAD_INIT

person groups was expected to be iterable but was None