Skip to Content
Bad Data 技術手冊
book

Bad Data 技術手冊

by Q. Ethan McCallum
September 2013
Intermediate to advanced
264 pages
5h
Chinese
GoTop Information, Inc.
Content preview from Bad Data 技術手冊
58
|
第四章:隱藏在純文字中的壞資料
-"€5, please"-
>>> print(s.decode('iso-8859-1'))
-5, please-
>>> print(len(s.decode('cp1252')))
14
>>> print(len(s.decode('iso-8859-1')))
14
我們現在知道未知編碼的文字能夠成為壞資料。除此之外,更糟糕的是擁有錯誤文字的
編碼,如將 Code Page 1252 ISO-8859-1 搞混,也是一種壞資料。
猜測文字編碼
Unix
file
工具會決定檔案中的資料是什麼型態。它能夠理解廣泛的檔案型態,包含一
些純文字的字元編碼。在範例 4-2 中的 Python 腳本程式使用不同的編碼產生一些文字資
料。
make_alnum_sample
函式會遞迴的執行前
n
Unicode 編碼點來尋找字母與數字的
字元。
codec
參數是用來指定撰寫這些字母與數字字元的編碼方式。
範例
4-2 
產生測試資料
>>> def make_alnum_sample(out, codec, n):
"""
Look at the first n unicode code points
if that unicode character is alphanumeric
and can be encoded by codec write the encoded
character to out
"""
for x in xrange(n):
try:
u ...
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

RxJava反应式编程

RxJava反应式编程

Tomasz Nurkiewicz, Ben Christensen
高效能PYTHON程式設計

高效能PYTHON程式設計

Micha Gorelick, Ian Ozsvald
Kubernetes编程

Kubernetes编程

Michael Hausenblas, Stefan Schimanski

Publisher Resources

ISBN: 9789862768952