1

Pythonスクリプトを使用して、ファイルのデータを他のファイルにコピーしています

input_file = open('blind_willie.MP3', 'rb')
contents = input_file.read()
output_file = open('f2.txt', 'wb')
output_file.write(contents)

テキスト エディタを使用して f2 を開くと、次のような記号が表示されます。

ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿù`‘~ +Pg]Nñòs

f2 ファイルのバイナリ コンテンツを表示する方法はありますか?

4

1 に答える 1

4

はい、ファイルのバイナリ コンテンツを表示する方法があり、f2それを発見しました。これらの記号は、ファイルのバイナリ コンテンツを表します。

バイナリ コンテンツの人間が読める解釈を見たい場合は、16 進ダンプ プログラムまたは 16 進エディタのようなものが必要になります。

Linux では、hdorod -t x1コマンドを使用します。

独自の 16 進ダンプ コマンドを作成する場合は、次のいずれかから始めることができます。

または、次のコードを使用できます。

def hd(data):
    """ str --> hex dump """
    def printable(c):
        import string
        return c in string.printable and not c.isspace()
    result = ""
    for i in range(0, len(data), 16):
        line = data[i:i+16]
        result += '{0:05x} '.format(i)
        result += ' '.join(c.encode("hex") for c in line)
        result += " " * (50-len(line)*3)
        result += ''.join(c if printable(c) else '.' for c in line)
        result += "\n"
    return result

input_file = open('blind_willie.MP3', 'rb')
contents = input_file.read()
output_file = open('f2.txt', 'wb')
output_file.write(hd(contents))
于 2013-04-03T13:34:11.087 に答える