em đang tập tành học python thông qua những video trên youtube của anh đạt nhưng khi làm tới bài đọc và ghi file thì mắc lỗi, em chạy python trên nền của máy Mac và khi em run đoạn code này :
from sys import argv
script = argv
filename = argv
print("We're going to ease %r" % (filename))
print("If you don't want that, hit CTRL-C (^C)")
print("If you do wan 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()
thì mắc lỗi này (Opening the file…
Traceback (most recent call last):
File "test.py", line 13, in <module>
target = open(filename, "w")
TypeError: expected str, bytes or os.PathLike object, not list)
và em không biết cách fix như thế nào mong được các cao nhân giúp đỡ
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?