Skip to Content
Fluent Python 第2版 ―Pythonicな思考とコーディング手法
book

Fluent Python 第2版 ―Pythonicな思考とコーディング手法

by Luciano Ramalho, 牧野 聡
November 2025
Intermediate to advanced
984 pages
16h 17m
Japanese
O'Reilly Japan, Inc.
Content preview from Fluent Python 第2版 ―Pythonicな思考とコーディング手法

4章Unicode文字列とバイト列

人間は文字を使い、コンピュータはバイト列で会話します。

—— Esther Nam、Travis Fischer

『Character Encoding and Unicode in Python』†1

[†1] PyCon 2014での講演『Character Encoding and Unicode in Python』(https://fpy.li/4-1)の12ページより。動画(https://fpy.li/4-2)も公開されています。

Python 3から、人間が読む文字列と生のバイトによるシーケンスとが明確に区別されるようになりました。暗黙のうちにバイト列がUnicode文字列に変換されるようなことは、もうなくなりました。この章ではUnicode文字列とバイナリシーケンスを扱い、両者間の変換に使われるエンコード形式について解説します。

読者がPythonで行う作業の種類によっては、Unicodeへの理解はさほど必要ないと思われることもあるかもしれません。しかしいずれにせよ、strbytesの違いを無視することはできません。両者の違いを学んでゆくと、特化したバイナリシーケンスにはPython 2の言わば汎用的なstr型にはない機能が含まれていることもわかるでしょう。

この章で扱うトピックは以下の通りです。

  • 文字、コードポイント、バイト表現
  • バイナリシーケンス(bytesbytearraymemoryview)に固有の機能
  • Unicodeの全域と従来の文字セットのためのエンコード形式
  • エンコードのエラーへの対応と回避策
  • テキストファイルを扱う際のベストプラクティス
  • デフォルトのエンコード形式や標準入出力でのありがちな問題
  • 正規化済みのUnicode文字列を使った安全な比較 ...
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

Fluent Python ―Pythonicな思考とコーディング手法

Fluent Python ―Pythonicな思考とコーディング手法

Luciano Ramalho, 豊沢 聡, 桑井 博之, 梶原 玲子
Architecture Patterns with Python

Architecture Patterns with Python

Harry Percival, Bob Gregory

Publisher Resources

ISBN: 9784814401284Publisher Website