需求
不管是上面的dot还是这个dot
变成
input输入文本
按"# ꧂ ꧁"结束
保存在dot文本文件夹下,
用txt保存每个文件文件名:
编号. 第二行有字文字 时间戳
代码
首先,我会创建一个Python脚本,它将接受用户的输入,直到输入以# ꧂ ꧁
结束,然后将输入保存为.dot
文件和对应的.txt
文件。代码如下:
python
import os
from datetime import datetime
def save_input_to_files():
input_text = ""
file_number = 1
while True:
line = input().strip()
if line == "# ꧂ ꧁":
break
input_text += line + "\n"
# 生成时间戳
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# 写入到dot文件中
dot_filename = f"{file_number}.dot"
with open(dot_filename, "w") as dot_file:
dot_file.write(input_text)
# 写入到txt文件中
txt_filename = f"{file_number}.txt"
with open(txt_filename, "w") as txt_file:
txt_file.write(f"File Number: {file_number}\n")
txt_file.write(f"Timestamp: {timestamp}\n")
txt_file.write(input_text)
print(f"Input saved to {dot_filename} and {txt_filename}")
file_number += 1
if __name__ == "__main__":
save_input_to_files()