練習附加題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