简体   繁体   中英

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. I've heard there's a way using python but I'm unsure how to. Any suggestions?

You can use chr() for this, for example:

t = "BLA"
t += chr(33)
print(t)

will print BLA! . 33 is the decimal value for "!". 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).

Edit: Use

file_ptr = open("filename.txt", "r")
t = file_ptr.read()

for example to grab your file's contents.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM