python下将文件以二进制形式保存

项目需要,别人的代码,觉得挺实用 放上来


#!/usr/bin/env python

infile = file("in.mp3","rb")
outfile = file("out.txt","wb")
def main():
    while 1:
        c = infile.read(1)
        if not c:
            break
        outfile.write(hex(ord(c)))
    outfile.close()
    infile.close()
if __name__ == '__main__':
    main()

你可能感兴趣的:(c,python,File,hex)