如何用python创建文本文件(.txt文件)?
这里给出示例脚本:
# Open the file in write mode
with open("test.txt", "w") as file:
# Iterate over the range and write each line to the file
for i in range(100):
file.write(f"{i}\n")
print("File 'test.txt' has been created successfully.")
这个脚本将会创建一个test.txt文件,其内容为1至100。
通过python脚本,可以快速创建有规律的文本。