<?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_-_Input_Output</id>
	<title>Example code - Input Output - 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_-_Input_Output"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Example_code_-_Input_Output&amp;action=history"/>
	<updated>2026-04-24T08:22:33Z</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_-_Input_Output&amp;diff=25&amp;oldid=prev</id>
		<title>WikiSysop: Created page with &quot;== Replacing tabs with spaces == As you may have discovered by now, Python is very sensitive about mixing tabs and spaces in the indentation. This program discovers all the tabs and makes them into spaces. You can decide how many spaces a tab should be.&lt;br&gt; The program is meant to work in a Unix environment, and Jupyter Notebook will tend to make it superfluous.  &lt;pre&gt; filename = input(&quot;Filename: &quot;) spaceno = int(input(&quot;Number of spaces instead of a tab: &quot;))  # Make a st...&quot;</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?title=Example_code_-_Input_Output&amp;diff=25&amp;oldid=prev"/>
		<updated>2024-03-01T15:52:40Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== Replacing tabs with spaces == As you may have discovered by now, Python is very sensitive about mixing tabs and spaces in the indentation. This program discovers all the tabs and makes them into spaces. You can decide how many spaces a tab should be.&amp;lt;br&amp;gt; The program is meant to work in a Unix environment, and Jupyter Notebook will tend to make it superfluous.  &amp;lt;pre&amp;gt; filename = input(&amp;quot;Filename: &amp;quot;) spaceno = int(input(&amp;quot;Number of spaces instead of a tab: &amp;quot;))  # Make a st...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Replacing tabs with spaces ==&lt;br /&gt;
As you may have discovered by now, Python is very sensitive about mixing tabs and spaces in the indentation. This program discovers all the tabs and makes them into spaces. You can decide how many spaces a tab should be.&amp;lt;br&amp;gt;&lt;br /&gt;
The program is meant to work in a Unix environment, and Jupyter Notebook will tend to make it superfluous. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
filename = input(&amp;quot;Filename: &amp;quot;)&lt;br /&gt;
spaceno = int(input(&amp;quot;Number of spaces instead of a tab: &amp;quot;))&lt;br /&gt;
&lt;br /&gt;
# Make a string with the correct amount of spaces&lt;br /&gt;
spacestring = &amp;quot;&amp;quot;&lt;br /&gt;
for i in range(spaceno):&lt;br /&gt;
    spacestring += &amp;quot; &amp;quot;&lt;br /&gt;
&lt;br /&gt;
# open infile in current directory for reading&lt;br /&gt;
infile = open(filename, &amp;quot;r&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# read line by line, until the end of file&lt;br /&gt;
content = &amp;quot;&amp;quot;&lt;br /&gt;
for line in infile:&lt;br /&gt;
    # iterate over characters in the string &amp;#039;line&amp;#039;&lt;br /&gt;
    for char in line:&lt;br /&gt;
        # if it&amp;#039;s not a tab character, just keep it unchanged&lt;br /&gt;
        if char != &amp;quot;\t&amp;quot;:&lt;br /&gt;
            content += char&lt;br /&gt;
        else:&lt;br /&gt;
            # replace with spacestring&lt;br /&gt;
            content += spacestring&lt;br /&gt;
infile.close()&lt;br /&gt;
&lt;br /&gt;
# open output file for writing&lt;br /&gt;
outfile = open(filename, &amp;quot;w&amp;quot;)&lt;br /&gt;
outfile.write(content)&lt;br /&gt;
outfile.close()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>