Python : error with importing md5
<p>I have problem with importing  md5 library
I just use the code below:</p>

<pre><code>import md5
filemd5 = md5.new(password.strip()).hexdigest()
</code></pre>

<p>I also have tried this code :</p>

<pre><code>from hashlib import md5
filemd5 = md5.new(password.strip()).hexdigest()
</code></pre>

<p>also this code :</p>

<pre><code>from md5 import md5
</code></pre>

<p>But none of them are working !
when I run the code,it gives me this error:</p>

<pre><code>11.py", line 1, in &lt;module&gt;
import md5
ImportError: No module named 'md5'
</code></pre>

<p>What Should I Do ?
Am I Importing The Wrong Library ?</p>

<p><code>md5</code> is not a module, it is an object. But it has no <code>new</code> method. It just has to be built, like any object.</p>

<p>Use as follows:</p>

<pre><code>import hashlib

m=hashlib.md5(bytes("text","ascii"))   # python 3
m=hashlib.md5("text")   # python 2
print(m.hexdigest())
</code></pre>

<p>results in:</p>

<pre><code>1cb251ec0d568de6a929b520c4aed8d1
</code></pre>

<p>You can also create the object empty and update it afterwards (more than once!)</p>

<pre><code>m=hashlib.md5()
m.update("text")   # python 2
m.update(bytes("text","ascii")) # python 3
</code></pre>

<p>note that Python 3 requires an encoded <code>bytes</code> object, not <code>string</code>, because Python 3 makes a difference between string and binary data. MD5 is useful on binary and strings.</p>

python md5