Python 3.x 为什么这个脚本没有';像xxd一样打印输出

Python 3.x 为什么这个脚本没有';像xxd一样打印输出,python-3.x,Python 3.x,我在一个教程的帮助下写了一个hextump,但我需要它不能完全像xxd输出那样显示。请告诉我我需要改变什么 import sys import argparse parser = argparse.ArgumentParser() parser.add_argument("file", help="Input File") args = parser.parse_args() try: with open (args.file, 'rb') as infile: with open (

我在一个教程的帮助下写了一个hextump,但我需要它不能完全像xxd输出那样显示。请告诉我我需要改变什么

import sys
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("file", help="Input File")
args = parser.parse_args()

try:
 with open (args.file, 'rb') as infile:
  with open (args.file+".dump", 'w') as outfile:        #opening a with .dump extension to save the output
        offset = 0
        while True:
            line = infile.read(16)          #reading the input file as 16 byte
            if len(line) == 0:
                break
            text = str(line)
            output ="{:08x}".format(offset)+ ":"    #generating the offset with 8 zeores in hex format "x"
            output+=" ".join([f"{a:02X}" for a in line[:8]])
            output+="  "                        #space between 8 hex byte
            output+=" ".join([f"{a:02x}" for a in line[8:]])
            output+="    " + text

            print (output)
            outfile.write(output + '\n')        #writing the output to .dump file
            offset += 16





except:
print ("Input File not found!!")        #exception if input file is not present
这是我需要的输出 00000000:4469 6c73 6861 6e20 4c61 6b73 6869 7468 Dilshan Lakshith 00000010:6120 0a4e 6962 6d0a a.Nibm。 这是我从脚本中得到的输出,我需要四个数字,而不是两个 00000000:44 69 6C 73 68 61 6E 20 4c 61 6b 73 68 69 74 68 b'Dilshan Lakshith' 000000 10:61 20 0A 4E 69 62 6D 0A b'a\nNibm\n'
它输出什么?您希望它输出什么?它从命令行参数输入一个文件,我需要输出一个与xxd输出完全相同的hexdump,我上传了一张图片供您选择。请编辑您的问题,并提供一个示例,说明您给出的内容,以及您希望得到的结果,对于给定的输入,你将得到什么。不要附加图像。那本书甚至不可读。改为复制和过去并编辑您的问题。请检查此项 This is the output I needed 00000000: 4469 6c73 6861 6e20 4c61 6b73 6869 7468 Dilshan Lakshith 00000010: 6120 0a4e 6962 6d0a a .Nibm. This is the output I get from my script I need this to be in four numbers but not two's 00000000:44 69 6C 73 68 61 6E 20 4c 61 6b 73 68 69 74 68 b'Dilshan Lakshith' 00000010:61 20 0A 4E 69 62 6D 0A b'a \nNibm\n'