如何在ASCI python中转义两个数字

问题描述 投票:0回答:1

我需要附加以 ASCI 字符中的数字开头的文件名。 例如,这就是我正在做的事情

import zlib

original_data = open('103354346.xlsm', 'rb').read()
compressed_data = zlib.compress(original_data, 6)
f = open('103354346.zzz', 'wb')
f.write(b' \010\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0GX\x8C\0\0\0\0\0\0\0\0\0\103354346.xlsm\0\0\0')

f.write(compressed_data)
f.close()

但是在这个文件名和文件名之间有一个空格。当前有空格。 无论如何,我们可以删除空间吗?

我们还需要在 Between 中添加 GXŒ 字符,但无法找到正确的值。

请帮忙

python ascii
1个回答
0
投票

只需删除字符串中的空格即可:

filename = '103354346.xlsm'
file_bytes = b'\010\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0GX\274\0\0\0\0\0\0\0\0\0 ' + filename.encode()
file_bytes = file_bytes.replace(b' ', b'')
f.write(file_bytes)

关于字符

GXŒ
Œ
的 ASCII 值为 140:

filename = '103354346.xlsm'
file_bytes = b'\010\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0GX' + bytes([140]) + b'\0\0\0\0\0\0\0\0\0' + filename.encode()
f.write(file_bytes)
© www.soinside.com 2019 - 2024. All rights reserved.