[英]Problem creating a text file with name provided by input
i am creating a txt file based on user input,But it creates files without any format, i am new to python can anyone help me.. 我正在基于用户输入创建txt文件,但是它创建的文件没有任何格式,我是python的新手,任何人都可以帮助我。
import os
name = input("Name :")
roll = input("Roll No :")
branch = input("Branch :")
add ="name :" + name + "\n" +"Roll No :" + roll +"\n" +"Branch :"+branch
f = open(name,"a+")
m = os.path.join(name +".txt")
f.write(add)
want to get name
+
".txt" file for each user 想要为每个用户获取
name
+
“ .txt”文件
output now is name
现在输出的是
name
import os
name = input("Name :")
roll = input("Roll No :")
branch = input("Branch :")
add ="name :" + name + "\n" +"Roll No :" + roll +"\n" +"Branch :"+branch
f = open(name + ".txt","a+") # This is where you are opening the file
# Below line is not contributing to the posted code at all
# m = os.path.join(name +".txt")
f.write(add)
f.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.