我正在做 Zed Shaw 的“Learn Python The Hard Way”中的练习,练习 16 似乎不想工作:
#!/usr/bin/python
# -*- coding: utf-8 -*-
# reading and writing files
from sys import argv
script, filename = argv
print "We're going to erase %r." % filename
print "If you don't want that, hit CTRL-C (^C)."
print "Otherwise, press [ENTER] to proceed."
raw_input = ("?")
print "Opening the file...."
target = open(filename, 'w')
print "Truncating the file...."
target.truncate()
print "Enter three lines of input...."
line1 = raw_input("line 1: ")
line2 = raw_input("line 2: ")
line3 = raw_input("line 3: ")
print "Writing to the file...."
target.write(line1)
target.write("\n")
target.write(line2)
target.write("\n")
target.write(line3)
target.write("\n")
print "Closing the file...."
target.close()
# end program
无论出于何种原因,每次我运行它时,它都会返回:
mark@mark-KC880AA-ABA-m9150f:/media/KINGSTON/cis-115-09/LPTHW$ python ex16.py ex15Sample.txt
We're going to erase 'ex15Sample.txt'.
If you don't want that, hit CTRL-C (^C).
Otherwise, press [ENTER] to proceed.
Opening the file....
Truncating the file....
Enter three lines of input....
Traceback (most recent call last):
File "ex16.py", line 24, in <module>
line1 = raw_input("line 1: ")
TypeError: 'str' object is not callable
无论我做什么, line1 变量似乎都会造成麻烦。我已经玩了一个多小时了。有什么建议吗?