标签:传递 sys pydoc splay who one count iter 运行
回忆一下函数的要点,然后一边做这节练习,一边注意一下函数和文件是如何在一起协作发挥作用的。
1 from sys import argv 2 3 script, input_file = argv 4 5 def print_all(f): 6 print f.read() 7 8 def rewind(f): 9 f.seek(0) 10 11 def print_a_line(line_count, f): 12 print line_count, f.readline() 13 14 current_file = open(input_file) 15 16 print "First let‘s print the whole file:\n" 17 18 print_all(current_file) 19 20 print "Now let‘s rewind, kind of like a tape." 21 22 rewind(current_file) 23 24 print "Let‘s print three lines:" 25 26 current_line = 1 27 print_a_line(current_line, current_file) 28 29 current_line = current_line + 1 30 print_a_line(current_line, current_file) 31 32 current_line = current_line + 1 33 print_a_line(current_line, current_file)
特别注意一下,每次运行 print_a_line 时,我们是怎样传递当前的行号信息的。
1.
标签:传递 sys pydoc splay who one count iter 运行
原文地址:http://www.cnblogs.com/yllinux/p/7420559.html