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 技術手冊 第三版
201
6
模組
一個典型的 Python 程式是由數個原始碼檔案(source files)所構成。每個
原始碼檔案都是一個
模組
module
,將程式碼與資料包成一組以便再利
用。一般來說,模組都彼此獨立,如此其他程式就能重複使用它們所需的
特定模組。有的時候,為了管理複雜度,你會將相關的模組包在一起成為
一個
套件
package
,一種階層式的樹狀結構。
一個模組會使用
import
from
述句明確地建立與其他模組的依存關係
dependencies)。在某些程式語言中,全域變數(global variables)提
供了一種隱藏的管道用於模組之間的接合(coupling)。 Python 中,全
域變數並不是對所有模組來說都是全域的,而只是單一模組物件的屬性
attributes)。因此,Python 的模組永遠都會以明確且可維護的方式進行
溝通。
Python 也支援
擴充模組
extension modules
的使用,它們是以其他語言
(例如 CC++Java C#)編寫的模組。對於匯入(import)一個模
組的 Python 程式碼而言,該模組是純 Python 的模組還是擴充模組並不重
要。你永遠都可以先用 Python 編寫一個模組,之後,如果你需要速度的
話,你再以較低階的語言重構(refactor)及重新編寫模組的某些部分,
而不必變更用到那些模組的客戶端程式碼。第 24 章會示範如何以 C
Cython 撰寫擴充功能(extensions)。
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