2025-09-10:仓库迁移
This commit is contained in:
10
5.文件与IO/2.将输出重定向到文件中.py
Normal file
10
5.文件与IO/2.将输出重定向到文件中.py
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 如果想要将东西输出到文件中,可以在print函数中指定file字段
|
||||
# print函数的默认结尾是\n,如果想要替换这个默认结尾,可以在end字段设置
|
||||
path = r"5.文件与IO/2.somefile.txt"
|
||||
with open(path, "at") as f:
|
||||
for i in range(10):
|
||||
print(i, file=f, end=' ')
|
||||
print("Done")
|
Reference in New Issue
Block a user