简体   繁体   English

如何使用 python 将较低级别的 ASCII 字符附加到(记事本)文档中?

[英]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).使用您喜欢的任何其他值,遍历您的字符串并将其写入一个新文件(使用openreadwrite ,当然要在文件库上完成此操作)。

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.

相关问题 在公共函数或较低级别的私有函数上使用Python的lru_cache / memoize功能是否更好,还是重要? - Is it better to use Python's lru_cache / memoize feature on public functions or lower-level private functions, or does it matter? 找出向同一层级或较低层级或上层层级报告的员工 - python - Find out emps reporting to same level hierarchy or lower-level hierarchy or superior-level hierarchy - python 按较低级别的值对字典字典进行排序 - Sort dictionary of dictionaries by value of lower-level Python 中嵌套字典中具有特定下级键的键的查询列表 - Query list of keys having a specific lower-level key in a nested dictionary in Python 如何使用 Python 计算文本文档中的唯一单词(没有特殊字符/大小写干扰) - How can you use Python to count the unique words (without special characters/ cases interfering) in a text document 在多标签分类中将参数传递给较低级别的 XGBoost 估计器 - Pass parameters to lower-level XGBoost estimators in multilabel classification Pandas 在 MultiIndex DataFrame 中选择特定的较低级别的列 - Pandas select specific lower-level columns in MultiIndex DataFrame 如何使用 for 循环在 python 中附加数组? - How can you use a for loop to append an array in python? 将 Pandas 数据帧中上层聚合的值连接到下层聚合 - Join Values from Upper-Level Aggregates to Lower-Level Aggregates in a Pandas Data Frame 使用较低级别的数据过滤分层Pandas Dataframe中的顶级类别 - Filtering top-level categories in hierarchical Pandas Dataframe using lower-level data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM