input输入多行文本,保存为.dot文件和对应的.txt文件

需求

复制代码
不管是上面的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()
相关推荐
deephub6 分钟前
Lux 上手指南:让 AI 直接操作你的电脑
人工智能·python·大语言模型·agent
Channing Lewis8 分钟前
Python读取excel转成html,并且复制excel中单元格的颜色(字体或填充)
python·html·excel
小钟不想敲代码10 分钟前
Python(一)
开发语言·python
大佬,救命!!!13 分钟前
对算子shape相关的属性值自动化处理
python·算法·自动化·学习笔记·算子·用例脚本·算子形状
WoY202018 分钟前
本地PyCharm配置远程服务器上的python环境
服务器·python·pycharm
tzjly26 分钟前
JSON数据一键导入SQL Server
python
一分半心动1 小时前
清理C盘的python脚本
开发语言·python
AI手记叨叨1 小时前
Python数学:几何运算
python·数学·解析几何·射影几何·微分几何·欧几里得几何
toolhow2 小时前
SelfAttenion自注意力机制
pytorch·python·深度学习
智航GIS2 小时前
6.2 while循环
java·前端·python