Pythonを学び、ユーザーがテキストの行を変更できるようにするスクリプトを書こうとしているだけです。何らかの理由で、置換する行を入力するようにユーザーに求めると、このエラーが発生します。
トレースバック(最後の最後の呼び出し):ファイル "textedit.py"、10行目、f.write(line1)AttributeError:'str'オブジェクトに属性'write'がありません
およびスクリプト自体:
f = raw_input("type filename: ")
def print_text(f):
print f.read()
current_file = open(f)
print_text(current_file)
commands = raw_input("type 'e' to edit text or RETURN to close the file")
if commands == 'e':
line1 = raw_input("line 1: ")
f.write(line1)
else:
print "closing file"
current_file.close()