AttributeError: 'file' object has no attribute 'encode'
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>Traceback (most recent call last):
  File "E:\blahblahblah\emailsend.py", line 26, in &lt;module&gt;
    msg.attach(MIMEText(file))
  File "E:\blahblahblah\Python 2.7.11\lib\email\mime\text.py", line 30, in __init__
    self.set_payload(_text, _charset)
  File "E:\blahblahblah\Python 2.7.11\lib\email\message.py", line 226, in set_payload
    self.set_charset(charset)
  File "E:\blahblahblah\Python 2.7.11\lib\email\message.py", line 268, in set_charset
    cte(self)
  File "E:\blahblahblah\Python 2.7.11\lib\email\encoders.py", line 73, in encode_7or8bit
    orig.encode('ascii')
AttributeError: 'file' object has no attribute 'encode'https://stackoverflow.com/questions/ask#</code></pre>
</div>
</div>
</p>

<p>I've been looking this up a lot but I haven't found an answer.</p>

<p>The only important parts of the code is this:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>file = open('newfile.txt')

msg.attach(MIMEText(file))</code></pre>
</div>
</div>
</p>

<p>There are other parts but I've debugged it and I get the error at the 'msg.attach(MIMEText(file))' line.</p>

<p>Any help?</p>