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 技術手冊 第三版
766
|
24 章 擴充與內嵌標準型的 Python
內嵌 Python
如果你已經有一個以 C C++(或其他典型的編譯語言)撰寫的應用程
式,你可能會想要內嵌 Python 作為你應用程式的指令稿語言(scripting
language)。要在 C 以外的語言中內嵌 Python,那個其他的語言必須能夠
呼叫 C 函式(你要如何那樣做,會隨著情況而變,不只是依據語言,還取
決於特定的語言實作:用的是什麼編譯器、什麼連結器等等)。接下來,
我們涵蓋 C 的觀點,其他語言,則如前面提到的,很大程度上取決於為了
從它們呼叫 C 函式,你必須做些什麼。
安裝常駐的擴充模組
為了讓 Python 指令稿與你的應用程式溝通,你的應用程式必須提供帶
Python 可取用的函式和類別的擴充模組,以對外提供你應用程式的功
能性。若是,如同一般情況,這些模組連結至你的應用程式(而非位在
Python 可在必要時載入的動態程式庫中),就呼叫
PyImport_AppendInittab
C API 函式向 Python 註冊你的模組為額外的內建模組:
PyImport_AppendInittab int PyImport_AppendInittab(char*
name,void (*initfunc)(void))
name
是模組名稱,Python 指令稿會用它來匯入該模組。
initfunc
是模組的初始化函式,不取引數,也不回傳結果,如
前面「初始化模組」中所涵蓋的(也就是說,
initfunc
是模組
的函式 ...
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