好​​的,考虑到要求。 f = file(''mybinfile'') contents = f.read()。replace(oldbinstring,newbinstring) f.close() f = file('' mybinfile'',''w'') f.write(内容) f.close()会这样做,并准确地做到。但它也会将整个文件读入内存。 Okay, given the requirements. f = file(''mybinfile'') contents = f.read().replace(oldbinstring, newbinstring) f.close() f = file(''mybinfile'',''w'') f.write(contents) f.close() Will do it, and do it accurately. But it will also read the entire file into memory. 32Kb确实是一个小文件,在内存中读取它不是问题! 人们有时喜欢编写长Python程序。这是关于 相同,更短一些::-) buffer = file(''mybinfile'',''rb'')。 read()。replace(oldbinstring,newbinstring) file(''mybinfile'',''wb'')。write(buffer) - - Fran?ois Pinard http://pinard.progiciels-bpi .ca 这篇关于在.bin文件中查找/替换长二进制模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-16 16:59