How to reuse an instance of hashlib.md5

Steve picture Steve · Nov 9, 2010 · Viewed 7.3k times · Source

How do you flush (or reset) and reuse an instance of hashlib.md5 in python? If I am performing multiple hashing operations in a script, it seems inefficient to use a new instance of hashlib.md5 each time, but from the python documentation I don't see any way to flush or reset the instance.

Answer

Ned Batchelder picture Ned Batchelder · Nov 9, 2010

Why do you think it's inefficient to make a new one? It's a small object, and objects are created and destroyed all the time. Use a new one, and don't worry about it.