I have this .py file:
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 "If you do want that, hit RETURN."
raw_input("?")
print "Opening the file..."
target = open(filename, 'w')
print "Truncating the file. Goodbye!"
target.truncate()
print "Now I'm going to ask you for three lines."
line1 = raw_input("line 1: ")
line2 = raw_input("line 2: ")
line3 = raw_input("line 3: ")
print "I'm going to write these to the file."
target.write(line1)
target.write("
")
target.write(line2)
target.write("
")
target.write(line3)
target.write("
")
print "And finally, we close it."
target.close()
What I do not understand:
a) Why in the interpreter if I write, raw_input("?")
, then type f
and press enter, it outputs the 'f'
string and if I run the .py file it doesn't return me the 'f' string?
b) Also, python docs says: " The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. So, why does the line 7 gets printed on a new line instead of line 6("?Opening the file..."). Where is that
coming from?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…