Skip to Content
Python 技術手冊 第三版
book

Python 技術手冊 第三版

by lex Martelli, Anna Martelli Ravenscroft, Steve Holden
January 2018
Intermediate to advanced content levelIntermediate to advanced
856 pages
17h 17m
Chinese
GoTop Information, Inc.
Content preview from Python 技術手冊 第三版
最小化語法差異
|
793
擁有大型源碼庫或對多版本相容性有強烈興趣的讀者,也應該閱讀 Lennart
Regebro 所著的
Porting to Python 3
http://python3porting.com/
,電子版或紙
本版都有)。那本書推出第二版的時候 Python 2.7 尚未出現,但其功能集已
經是相當為人所知的,而該書也含有很多我們不會在此重複的實用建議。
取而代之,我們涵蓋很有可能出現不相容性的幾個重點,在「最小化語法
差異」中,以及一些能夠協助你進行轉換的工具。
_ _future__
匯入
__future__
是含有各種功能的一個標準程式庫模組,記
載在線上說明文件(
https://docs.python.org/3/library/__
future__.html
)中,能夠幫助版本間的移轉工作。它不同於
任何其他的模組,因為匯入功能可能影響你程式的語法,
而非只是語意。這種匯入必須是你程式碼最初的可執行
述句。
每個「未來功能(future feature)」都是以這樣的述句來啟
用的:
from __future__ import feature
其中
feature
是你想要使用的功能。特別是,我們建議在
你的 v2 模組頂端放置下面這一行,以得到最佳的相容性。
from __future__ import (print_function, division,
absolute_import)
v2 底下,這會啟用 v3 列印、除法和匯入機制的相容功
能。
最小化語法差異
Python ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

測試驅動開發|使用 Python

測試驅動開發|使用 Python

Harry J.W. Percival
Linux 内核观测技术BPF

Linux 内核观测技术BPF

David Calavera, Lorenzo Fontana

Publisher Resources

ISBN: 9789864766819