混亂的 Python
常言道,Python 真諦之一是:
There should be one– and preferably only one –obvious way to do it.
才怪。雖說我不好說 Python 具體處于哪一種陣營,但它確實相當「混亂」。不信?且聽我一一道來。
版本大躍進
世界上最遠的距離之一是,我用 Python 2, 您用 Python 3.
不過, 在前三百六十的熱門 Python 項目中,支持 Python 3 的已經超過 85% 了 ,好事一樁。
版本管理和虛擬環境
關于Python 的版本和開發環境管理 一口氣介紹了種種版本管理和虛擬環境:Pyenv, Virtualenv, VirtualenvWrapper, Pyenv-Virtualenv, Pyenv-VirtualenvWrapper. (讓我喘口氣先
這還不夠,Python 3.4 突然蹦出全新的 Pyvenv 來。
網絡庫
Python 2 同時有官方模塊 urllib , urllib2 , 彼此獨立; urllib3 , urllib4 出自民間;最后一個 urllib5 就純屬搞怪的了:
Once there was urllib. Then there was urllib2. Then there was urllib3. And if you look at PyPI, you even find urllib4. If you want to have all of them, use urllib5. Or you know, have a nice urllib in the standard library. But that would be too easy. SCNR. HTH. lol
到 Python 3, urllib 更是分裂成幾個模塊:
- urllib.request for opening and reading URLs
- urllib.error containing the exceptions raised by urllib.request
- urllib.parse for parsing URLs
- urllib.robotparser for parsing robots.txt files
其實大家更愛用民間的 requests… 如果官方能用 request 一勞永逸地換掉那些「亂倫」的 urllib 系列就好了。
包管理
請看 Python Packaging 編年史 ,Disqus 里還有我的強力?補充。
我還順便在 #archlinux-cn 吐槽了 Python 的包管理,超級宇宙無敵之霹靂笨貓發話了:
[Felix Yan] 有興趣的話,可以分別試試 find /usr/lib/python2.7/site-packages -maxdepth 1 -name “ .egg-info” -type f | wc -l 和 find /usr/lib/python2.7/site-packages -maxdepth 1 -name “ .egg-info” -type d | wc -l
[Felix Yan] 前者是 distutils 安裝的結果,后者是 setuptools
我試了下,結果令我大吃一驚,還在用包管理(石)器 distutils 的居然有 20 個!笨貓聳聳肩,表示因為「有些開發者覺得 setuptools 的新功能沒啥用而已」。
Written with StackEdit .