嗨,我正在尝试使用预写标签以及给定的用户输入来创建几个文本文件。 对于前我需要5个带有预写标签和输入的文件名
Cat100.txt 其中cat是预先确定的,数字100是用户输入。
我有这个,但是我不知道如何在用户输入中添加预写标签。
filename = input ("filename: ");
with open (filename, "w") as f:
谢谢!
答案 0 :(得分:2)
每条评论均已更新:
import os
folderpath = ".\\test_folder\\"
prewritten_tag = "User wrote: " # example
user_filename = input("filename: ")
full_filename = prewritten_tag + user_filename
fullpath = os.join(folderpath,full_filename) # gets absolute path
with open(fullpath, "w") as f:
user_input = input()
full_txt = stuff + input() + otherstuff
f.write(full_txt)