Files
Python_CookBook_repo/5.文件与IO/18.将已有的文件描述符包装为文件对象.pyi
2025-09-10 16:12:45 +08:00

11 lines
363 B
Python
Raw Permalink 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 os
if __name__ == "__main__":
# open函数除了可以对文件对象进行操作以外也可以打开一些由系统创建的文件描述符
fd = os.open("5.文件与IO/17.try.txt", os.O_WRONLY | os.O_CREAT)
# 当文件被关闭时,这些由系统创建的IO管道也会随之关闭
f = open(fd, 'wt')
f.write("ca")
f.close()