I’m experimenting with a python program that will allow you to edit text files, I will use this feature later on in other programs, but I get the error: [errno 22] Invealid argument: ‘test.txt\r’. Also I never added \r to test.txt. Here is my code:
def menu():
print("Type in the full name of the text file you would like to add to.")
file1 = input()
with open(file1, "br") as add:
print("What do you want to write?")
text = input()
add.write(text)
menu()
Okay, new problem. I edited the code so that now it says file1 = input().strip() and it worked fine ALL up until I got another error. The error is: io:UnsupportedOperation: write. The error says it’s in line 7 in the part that says add.write(text).
Nevermind, I changed the with open(file1, "br") to with open(file1, "a") and it works fine now. THANKS FOR ALL OF YOUR HELP GUYS!!!
Use:
input()returns the new line at the end and that makes the filename invalid.