問題是這個樣子的 [crayon-64229c179dfe6429237121/] 為什麼會有 Python 2 不能運算 (-1) ** .5 而 Python 3 可以的狀況?直覺想就是 Python 2 的 integer __pow__ 並沒有支援 pow 運算轉型為 Complex,而在 Python 3 中會轉行為 Complex。但是要怎麼驗證這個行為? 編譯 CPython 並且使用 …
分類: Python-internals
CPython’s garbage collection relies on each object’s reference count. Each object has their own reference count, when the object is referenced by others, then we will need to increase objec …
本文將會探討 Python 內部的 Global Interpreter Lock,以及學習其如何影響 multi-threaded 程式。 原作者:A. Jesse,Twitter: @jessejiryudavis 原文:Grok the GIL: How to write fast and thread-safe Python Louie Lu 經作者同意[1][2]翻譯為正體中文。 當我6 …
Why Python standard library “profile” can’t be context manager like this [crayon-64229c179f1a0090484789/] Zero, what is “profile” module in Python? According to Pyt …
當 Python 在讀入程式碼的時候, 第一步就是對程式碼 lexing,將程式碼拆解成 token,標記出每個元素的分類為何。 以下面的程式碼為例: [crayon-64229c179f43f080364446/] 我們透過 tokenize module 來分析,會變成: [crayon-64229c179f444018421079/] 我們可以看到 foo 被標記為 NAME,= 標記為 OP …
你可曾想過這段 Python 程式碼是如何運作的? [crayon-64229c179f6b8013201921/] Python 作為 interpreted language,其運作可以分為兩個大項,Compiler 以及 Virtual Machine。Compiler 負責將輸入的語法做分析,轉換成 AST (Abstract Syntax Tree),再轉換成 CFG,最後依照 CFG 輸 …