title: Editing HTML page using python 3.5.2 and Dominate
body: <p>I have an HTML page which I want to edit using a python script. I am using the <a href="https://github.com/Knio/dominate" rel="nofollow noreferrer">Dominate</a> library</p>
  
  <p>Here's a barebones example.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;asdjasda&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;h1&gt;THIS IS A TEST&lt;/h1&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Simple HTML right?<br>
  Here's the python script: </p>
  
  <pre><code>import dominate
  from dominate.tags import *
  
  page = open('index.html','r',encoding='utf-8')
  
  with page.head:
      link(rel='stylesheet', href='tts.css')
  page.close()
  </code></pre>
  
  <p>I get the following error when I run this script.</p>
  
  <pre><code>Traceback (most recent call last):  
    File "script.py", line 6, in &lt;module&gt;  
      with page.head:  
  AttributeError: '_io.TextIOWrapper' object has no attribute 'head'
  </code></pre>
  
  <p>My HTML does have a 'head'. </p>
  
  <p>How do I use dominate to edit my file?</p>