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 技術手冊 第三版
序列化
|
387
值。
pickle
也會正確地序列化帶有參考循環(reference cycles)的圖。然
而,這也意味著,如果一個可變的物件
o
被多次序列化為相同的
Pickler
實體
p
,那麼
o
p
的第一次序列化之後對
o
所做的任何變更都不會被
儲存。
別在序列化的過程中變更物件
為了清晰度、正確性和簡單性,別在物件序列化為
Pickler
實體的過程中,更改那些被序列化的物件。
pickle
能以傳統的 ASCII 協定或幾個精簡的二進位協定之一進行序列化。
v2 中,ASCII 協定
0
是預設值,這是為了回溯相容性,但通常你應該明
確地請求二進位協定
2
,這個 v2 支援的協定能節省最多時間和空間。在 v3
中,協定的範圍從
0
4
(包含端點),預設為
3
,它通常是一個合理的選
擇,但你可以明確地指定協定
2
(以確保你所儲存的 pickles 可被 v2 程式
載入),或協定
4
,相容於早期版本,但在非常大型的物件上有效能優勢。
永遠都以協定
2
或更高的協定來進行
pickle
永遠都指定至少協定
2
。節省的空間和時間會很可觀,而
二進位格式基本上沒有缺點,除了所產生的 pickles 無法與
真的很老舊的 Python 版本相容以外。
當你重新載入物件,
pickle
會自動辨識並使用你目前的 Python 版本支援的
任何協定。
pickle
會以名稱序列化類別與函式,而非以它們的值。因此
pickle
解序列
化一個類別或函式的方式是從
pickle
序列化它的時候在其中找到那個類別
或函式的同一個模組匯入它。特別是,
pickle
通常只在類別或函式是它們 ...
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