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 是: bytes: b'\xff\xd8' 哪个是正确的?
所以我的字符串比较失败了。如何最好地解决这个问题?
谢谢
尝试这个:
if firstTwoBytes != b'\xff\xd8':
所以,比较二进制而不是字符串:
f = open(filename, 'rb') firstTwoBytes = f.read(2) if firstTwoBytes != b'\xff\xd8':