`File = input("Please enter the name for your txt. file: ")
fileName = (File + ".txt")
WRITE = "w"
APPEND = "a"
file = 
name = " "
while name != "DONE" :
name = input("Please enter the guest name (Enter DONE if there is no more names) : ").upper()
print("The guests list in alphabetical order, and it will save in " + fileName + " :")
for U in file :
file = open(fileName, mode = WRITE)
print("file written successfully.")
I am just practicing to write the file in Python, but something bad happened. Please help me. Thank you.
The error description.
Here are still some errors about this :
Still showing 'str' error.
You try to
append to string which is not correct in Python, instead try:
filename += 'name'
You're trying to build a list of names. Start with a list:
guests = 
and then append the values provided by your user:
while name is not "Done": prompt = "Please input the name of the next guest, or 'Done'." guests.append(input(prompt).upper())
then you can sort that list and write the values to the file. (which you seem to have a handle on)
Appending the guests' names to fileName, or concatenating them onto it, wouldn't make a lot of sense. You'd end up with something like "data.txtJOEBOBJANELINDA" which would do you no good at all.