Why python 2: negative number cannot be raised to a fractional power, but work on Python 3

問題是這個樣子的 [crayon-64229c179dfe6429237121/] 為什麼會有 Python 2 不能運算 (-1) ** .5 而 Python 3 可以的狀況?直覺想就是 Python 2 的 integer __pow__ 並沒有支援 pow 運算轉型為 Complex,而在 Python 3 中會轉行為 Complex。但是要怎麼驗證這個行為? 編譯 CPython 並且使用

Continue Reading

深入 GIL: 如何寫出快速且 thread-safe 的 Python – Grok the GIL: How to write fast and thread-safe Python

本文將會探討 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

Continue Reading

Python 底層運作 02 – PyTokenizer_Get 分析

當 Python 在讀入程式碼的時候, 第一步就是對程式碼 lexing,將程式碼拆解成 token,標記出每個元素的分類為何。 以下面的程式碼為例: [crayon-64229c179f43f080364446/] 我們透過 tokenize module 來分析,會變成: [crayon-64229c179f444018421079/] 我們可以看到 foo 被標記為 NAME,= 標記為 OP

Continue Reading