I can't open the file as a write file.
script = argv
filename = argv
print(f"We're going to erase {filename}. ")
print("If you don't want that, hit CTRL-C (^C). ")
print("If you do want that, hit RETURN. ")
input("?")
print("Opening the file...")
target = open(filename, 'w')
print("Truncating the file. Goodbye!")
target.truncate()
print("Now I'm going to ask you for three lines. ")
line1 = input("line 1: ")
line2 = input("line 2: ")
line3 = input("line 3: ")
print("I'm going to write these to the file. ")
target.write(line1)
target.write("\n")
target.write(line2)
target.write("\n")
target.write(line3)
target.write("\n")
print("And finally, we close it. ")
target.close()
It's giving this error:
line 14, in <module>
target = open(filename, 'w')
TypeError: expected str, bytes or os.PathLike object, not list
If I execute the code from terminal, It's giving me a syntax error for the last double quote of the first print statement.
line 6
print(f"We're going to erase {filename}. ")
^
SyntaxError: invalid syntax
To solve this I've changed the f-string to format.
print("We're going to erase {}. ".format(filename))
After I executed the code It gave me another error:
File "ex16.py", line 11, in <module>
input("?")
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
I don't know what to do.