使用输入提供的名称创建文本文件时出现问题
Problem creating a text file with name provided by input
我正在根据用户输入创建一个 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)
想要为每个用户获取 name
+
“.txt”文件
现在的输出是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()
我正在根据用户输入创建一个 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)
想要为每个用户获取 name
+
“.txt”文件
现在的输出是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()