![](/img/trans.png)
[英]Is it better to use Python's lru_cache / memoize feature on public functions or lower-level private functions, or does it matter?
[英]How can you use python to append lower-level ASCII characters to a (notepad) document?
我需要達到特定的字節數,並希望用空字節(例如較低級別的 ascii 字符)填充文檔的其余部分。 我聽說有一種使用 python 的方法,但我不確定如何使用。 有什么建議?
您可以為此使用chr()
,例如:
t = "BLA"
t += chr(33)
print(t)
將打印BLA!
. 33 是“!”的十進制值。 使用您喜歡的任何其他值,遍歷您的字符串並將其寫入一個新文件(使用open
、 read
和write
,當然要在文件庫上完成此操作)。
編輯:使用
file_ptr = open("filename.txt", "r")
t = file_ptr.read()
例如獲取文件的內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.