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.
JPEG の最初の数バイトを読み取る
f = open(filename, 'rb') firstTwoBytes = f.read(2) if firstTwoBytes != '\xff\xd8':
firstTwoBytes iny 私のデバッガーは: bytes: b'\xff\xd8' どちらが正しいですか?
だから私の文字列比較は失敗します。これを修正するにはどうすればよいですか?
ありがとう
これを試して:
if firstTwoBytes != b'\xff\xd8':
したがって、文字列ではなくバイナリと比較します。
f = open(filename, 'rb') firstTwoBytes = f.read(2) if firstTwoBytes != b'\xff\xd8':