Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ファイルから読み取るときに、またはbytesを使用すると、常にエラーが発生します。その理由は何ですか?ord()chr()
bytes
ord()
chr()
ファイルから読み取る場合byte、バイト文字として表されます (それを使用する必要がありますord())。
byte
>>> print(index_file.read(1)) b'\x0a'
バイト配列を読み取る場合、つまりbytearray、配列の各メンバーは単純にintなります (そして、それを使用する必要がありますchr())。
bytearray
int
>>> print(index_file.read(2)[0]) 10