Files
Python_CookBook_repo/5.文件与IO/17.将字节数据写入文本文件.py
2025-09-10 16:12:45 +08:00

12 lines
333 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import io
if __name__ == "__main__":
file = "5.文件与IO/17.try.txt"
# 上一章我们知道了文件打开后都长什么样子想要往文件里写字节数据怎么办直接往buffer里怼就完了、
# 这样可以绕过文件的编码层
f = open(file, "w")
f.buffer.write(b"write")
f.close()