练习附加题20我被告知要评论我认为每一行的含义。寻找我发现混乱。如果有人愿意查看我对源代码的评论,看看我是否理解正确。我可以跳过它,但我觉得它很重要,我明白这一点。学习python难题练习20帮助
感谢
from sys import argv #imports argv from sys moduel
script, input_file = argv #unpacks the startup arguments to script and input_file variables
def print_all(f): #defines a function that uses the read() function on whatever is in the parameter(current_file in this case)
print f.read()
def rewind(f): #not a clue what this does really...moves to byte 0 of the file??
f.seek(0)
def print_a_line(line_count, f): #sets a function that reads a line from the current_file
print line_count, f.readline()
current_file = open(input_file)
print 'first of all, lets read the wole file:\n'
print_all(current_file)
print 'now lets rewind, kind of like a tape'
rewind(current_file)
print 'lets print 3 lines:'
current_line = 1
print_a_line(current_line, current_file)
current_line = current_line + 1
print_a_line(current_line, current_file)
current_line = current_line + 1
print_a_line(current_line, current_file)
谢谢你们,剩下的是准确的? – neil 2011-03-07 20:53:59