Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. from sys import argv # imports a module
  2.  
  3. script, input_file = argv # you can give it the variable input_file a value when you run this script
  4.  
  5. def print_all(f): # a function not sure what (f) means?
  6.     print f.read() # reads the file
  7.    
  8. def rewind(f): # not sure what this does , but it is a function
  9.     f.seek(0) # not sure what seek means
  10.    
  11. def print_a_line(line_count, f): # not sure what f stands for again
  12.     print line_count, f.readline() # reads a file from the line
  13.    
  14. current_file = open(input_file) # opens the input file and gives it the variable of current_file
  15.  
  16. print "First lets print the whole file: \n"
  17.  
  18. print_all(current_file) # I'm guessing the f earliar was a placeholder for the actual file now current_file
  19.  
  20. print "Now lets reqind kind of like a tape." # simple print command
  21.  
  22. rewind(current_file) # not sure what this function did see line 8
  23.  
  24. print "Let's print three lines:" # simple print
  25.  
  26. current_line = 1 # gives value of 1 to current line
  27. print_a_line(current_line, current_file) # calls function from line 11-12 & gives it variables
  28.  
  29. current_line = current_line + 1 # same as above but the value of current line is + 1'd
  30. print_a_line(current_line, current_file)
  31.  
  32. current_line = current_line + 1 # same as above
  33. print_a_line(current_line, current_file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement