Example code - File Reading: Revision history

Jump to navigation Jump to search

Diff selection: Mark the radio buttons of the revisions to compare and hit enter or the button at the bottom.
Legend: (cur) = difference with latest revision, (prev) = difference with preceding revision, m = minor edit.

1 March 2024

  • curprev 17:3317:33, 1 March 2024WikiSysop talk contribs 629 bytes +629 Created page with "== Numbering and printing a chunk of file == <pre> print("Numbers and prints a section of a file.") filename = input("Filename: ") fromline = int(input("From line: ")) toline = int(input("To line: ")) with open(filename, "r") as infile: # keep track of the line number linenumber = 0 # iterate over the lines in the file for line in infile: linenumber += 1 # went past the required last line if linenumber > toline: pas..."