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

Python 技術手冊 第三版

by lex Martelli, Anna Martelli Ravenscroft, Steve Holden
January 2018
Intermediate 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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

利用 Python 进行数据分析(原书第2版)

利用 Python 进行数据分析(原书第2版)

Wes McKinney

Publisher Resources

ISBN: 9789864766819