用户使用raw_input()函数输入三组str, 只用一个.write()写入全部三组str
当初不清楚,纠结在.write()本身的语法。
后来一个for循环解决问题:
line1 = raw_input("line 1:")
line2 = raw_input("line 2:")
line3 = raw_input("line 3:")
lines = [line1,'\n',line2,'\n',line3,'\n']
for items in lines:
target.write(items)
后来又有个if循环,使用if Y == yes来判断,最后发现需要用Y == 'yes',需要用str来判断。
print "Do you want to read what you write just now?"
print "If you want,input 'yes';else input 'no'"
Y = raw_input("yes or no --->")
if Y == 'no':
sys.exit()
elif Y == 'yes':
target = file(filename)
print target.read()
target.close()
else:
print 'Error!! Please input \'yes\' or \'no\' The program will be exited!'
sys.exit()