from sys import argv
script, filename = argv
print "Opening file..."
program = open(filename)
print "File is truncating,..."
program.truncate
print "Let's write three lines."
line1 = raw_input("line 1: ")
line2 = raw_input('line 2; ')
line3 = raw_input("line 3: ")
print "Writing..."
program.write(line1)
program.write("\n")
program.write(line2)
program.write("\n")
program.write(line3)
program.write("\n")
print "Complete.."
program.close()
Đây là biến thể từ video của anh Đạt nhưng khi chạy thì nó kêu
Traceback (most recent call last):
File "py16-ontap.py", line 19, in <module>
program.write(line1)
IOError: File not open for writing
Vậy là sao ạ! Mình mở nó ở trên rồi hay là phải mởi lại 1 lần nữa sao???
Mong giải đáp giúp em!
ở cmt đó nhé.
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?