<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://teaching.healthtech.dtu.dk:443/22101/index.php?action=history&amp;feed=atom&amp;title=Example_code_-_File_Reading</id>
	<title>Example code - File Reading - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?action=history&amp;feed=atom&amp;title=Example_code_-_File_Reading"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Example_code_-_File_Reading&amp;action=history"/>
	<updated>2026-04-05T11:58:55Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Example_code_-_File_Reading&amp;diff=15&amp;oldid=prev</id>
		<title>WikiSysop: Created page with &quot;== Numbering and printing a chunk of file ==  &lt;pre&gt; print(&quot;Numbers and prints a section of a file.&quot;) filename = input(&quot;Filename: &quot;) fromline = int(input(&quot;From line: &quot;)) toline   = int(input(&quot;To line: &quot;))  with open(filename, &quot;r&quot;) 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 &gt; toline:             pas...&quot;</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Example_code_-_File_Reading&amp;diff=15&amp;oldid=prev"/>
		<updated>2024-03-01T15:33:12Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== Numbering and printing a chunk of file ==  &amp;lt;pre&amp;gt; print(&amp;quot;Numbers and prints a section of a file.&amp;quot;) filename = input(&amp;quot;Filename: &amp;quot;) fromline = int(input(&amp;quot;From line: &amp;quot;)) toline   = int(input(&amp;quot;To line: &amp;quot;))  with open(filename, &amp;quot;r&amp;quot;) 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 &amp;gt; toline:             pas...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Numbering and printing a chunk of file ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print(&amp;quot;Numbers and prints a section of a file.&amp;quot;)&lt;br /&gt;
filename = input(&amp;quot;Filename: &amp;quot;)&lt;br /&gt;
fromline = int(input(&amp;quot;From line: &amp;quot;))&lt;br /&gt;
toline   = int(input(&amp;quot;To line: &amp;quot;))&lt;br /&gt;
&lt;br /&gt;
with open(filename, &amp;quot;r&amp;quot;) as infile:&lt;br /&gt;
    # keep track of the line number&lt;br /&gt;
    linenumber = 0&lt;br /&gt;
    # iterate over the lines in the file&lt;br /&gt;
    for line in infile:&lt;br /&gt;
        linenumber += 1&lt;br /&gt;
        # went past the required last line&lt;br /&gt;
        if linenumber &amp;gt; toline:&lt;br /&gt;
            pass&lt;br /&gt;
        # reached the line we want to print from&lt;br /&gt;
        elif linenumber &amp;gt;= fromline:&lt;br /&gt;
            print(linenumber, &amp;quot;\t&amp;quot;, line, sep=&amp;#039;&amp;#039;, end = &amp;#039;&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>