just learning python and trying to write a script that allows the user to change lines in a text. For some reason I get this error when prompting the user to enter something for the line to be replaced:
Traceback (most recent call last): File "textedit.py", line 10, in f.write(line1) AttributeError: 'str' object has no attribute 'write'
and the script itself:
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()