[英]How can you use python to append lower-level ASCII characters to a (notepad) document?
I need to reach a specific byte count and want to fill the rest of document with null bytes such as lower-level ascii characters.我需要达到特定的字节数,并希望用空字节(例如较低级别的 ascii 字符)填充文档的其余部分。 I've heard there's a way using python but I'm unsure how to.
我听说有一种使用 python 的方法,但我不确定如何使用。 Any suggestions?
有什么建议?
You can use chr()
for this, for example:您可以为此使用
chr()
,例如:
t = "BLA"
t += chr(33)
print(t)
will print BLA!
将打印
BLA!
. . 33 is the decimal value for "!".
33 是“!”的十进制值。 Use any other value you like, loop over your string and write it to a new file (use
open
, read
, and write
, of course to accomplish this on a file base).使用您喜欢的任何其他值,遍历您的字符串并将其写入一个新文件(使用
open
、 read
和write
,当然要在文件库上完成此操作)。
Edit: Use编辑:使用
file_ptr = open("filename.txt", "r")
t = file_ptr.read()
for example to grab your file's contents.例如获取文件的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.