【发布时间】:2016-11-02 21:19:50
【问题描述】:
我是学习 python 的新手。我不明白为什么 print 命令会在屏幕上输出所有变量,但 write command to file 只写入 2 个前两个变量。
print "Opening the file..."
target = open(filename, 'a+')
line1 = raw_input("line 1: ")
line2 = raw_input("line 2: ")
line3 = raw_input("line 3: ")
line4 = line1 + "\n" + line2 + "\n" + line3
# This command prints all 3 (line1,line2,line3) variables on terminal
print line4
#This command only writes line1 and line2 variables in file
target.write(line4)
print "close the file"
target.close()
【问题讨论】:
标签: python