# coding=utf-8
import socket
import sys
import string
import re
import os
import struct
def read_bin_file(file_name):
file_object = open(file_name, 'rb')
try:
file_content = file_object.read(1)
finally:
file_object.close()
data = struct.unpack('B', file_content)
print "%x" %(data)
if __name__ == '__main__':
read_bin_file('abc.bin')
import socket
import sys
import string
import re
import os
import struct
def read_bin_file(file_name):
file_object = open(file_name, 'rb')
try:
file_content = file_object.read(1)
finally:
file_object.close()
data = struct.unpack('B', file_content)
print "%x" %(data)
if __name__ == '__main__':
read_bin_file('abc.bin')
本文介绍了一个使用Python读取二进制文件的基本示例,并展示了如何解析文件内容并打印出来。此示例利用了Python标准库中的struct模块来解析二进制数据。
3610

被折叠的 条评论
为什么被折叠?



