系统自带的 2.7 版本:
-----------------------
def print_a_line(f):
....for i in [1,2,3]:
........print("line %s: %s" % (i, f.readline()))
........f.truncate()
current_file = open(input_file,"w+")
current_file.write('''xxx.
yyy.
zzz.''')
current_file.seek(0)
print("Let's print three lines:")
print_a_line(current_file)
-----------------------
结果得到:
-----------------------
Let's print three lines:
line 1: xxx.
line 2:
line 3:
-----------------------
相同文件在版本 3.2 执行后得到:
-----------------------
Let's print three lines:
line 1: xxx.
line 2: yyy.
line 3: zzz.
-----------------------
肿么回事?我在读 Dive into Python ,翻看 2to3 那节也没看到说这个版本差异啊…
-----------------------
def print_a_line(f):
....for i in [1,2,3]:
........print("line %s: %s" % (i, f.readline()))
........f.truncate()
current_file = open(input_file,"w+")
current_file.write('''xxx.
yyy.
zzz.''')
current_file.seek(0)
print("Let's print three lines:")
print_a_line(current_file)
-----------------------
结果得到:
-----------------------
Let's print three lines:
line 1: xxx.
line 2:
line 3:
-----------------------
相同文件在版本 3.2 执行后得到:
-----------------------
Let's print three lines:
line 1: xxx.
line 2: yyy.
line 3: zzz.
-----------------------
肿么回事?我在读 Dive into Python ,翻看 2to3 那节也没看到说这个版本差异啊…