#!/usr/bin/env python

import hashlib

prefix = ''
number = 1

with open('../inputs/04.txt') as f:
   prefix = f.readlines()

prefix = prefix[0].rstrip()

while True:
   md5 = hashlib.md5()
   md5.update('{0}{1}'.format(prefix, number))

   if md5.hexdigest()[:6] == '000000':
      #print md5.hexdigest()
      print number
      break

   number += 1

#!/usr/bin/env python

import hashlib

prefix = ''
number = 1

with open('../inputs/04.txt') as f:
   prefix = f.readlines()

prefix = prefix[0].rstrip()

md5 = hashlib.md5()
md5.update(prefix)

while True:
   m = md5.copy()
   m.update(str(number))

   if m.hexdigest()[:6] == '000000':
      print number
      break

   number += 1

Use md5.copy() to be more efficient.