from sys import argv
script, in_file = argv
def print_all(f):
return f.read()
def rewind(f):
return f.seek(0)
def print_line_by_line(line_count, f):
return line_count, f.readline()
txt = open(in_file)
print "First, print all of the input file."
print print_all(txt)
print "Let us rewind it."
rewind(txt)
print "print line by line."
current_line = 1
print print_line_by_line(current_line, txt)
current_line = current_line + 1
print print_line_by_line(current_line, txt)
current_line = current_line + 1
print print_line_by_line(current_line, txt)
[问题]:print_line_by_line函数里的,为什么要有line_count变量,它是怎么起作用的?
哥啊!写python代码咱能好好写缩进吗!这么执行直接肯定报错啊! 打眼一看这个line_count 是为了记录行号。