我有相同的代码,我在 raspberry 和 win7 上运行它,但我无法得到相同的结果
代码:
with open('file','rb') as fd:
ttt = fd.read(4)
print (ttt)
seed = unpack('>I', fd.read(4))[0]
print str(seed)
在 linux 上我得到了很好的结果。
b')M7\xeb'
692926443
但是在 windows 上,我有
>M7ù
1401564715
为什么会有这种差异?为什么在 linux 上我有超过 4 个字符?
编辑: 我终于找到了一种方法来获得相同的结果。
import codecs
with codecs.open("G:/InsideReCaptcha-master/enc", mode='rb') as fd:
ttt = fd.read(4)
seed = unpack('>I', ttt)[0]
不确定所有代码是否有用,但它有效。
最佳答案
Linux 输出是二进制字符串表示,这就是它显示为 b'[STRING]' 的原因。重音字符显示为转义的 ASCII 替代字符。 Windows 输出是实际的字符串表示形式。要使它们相同,请使用解码:
print b'a string'.decode('ascii')
关于python - 读取文件,在 windows 或 linux 上的结果不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36653103/