text: #!/usr/bin/env python
  
  from __future__ import print_function
  from collections import defaultdict
  import sys
  import math
  import argparse
  
  
  def entropy(filename):
      frequencies = defaultdict(int)
      bufreadlen = 1024*32
      filesize = 0
      with open(filename, 'rb') as filehandle:
          buf = filehandle.read(bufreadlen)
          while buf:
              for c in buf:
                  frequencies[c] += 1
              filesize += len(buf)
              buf = filehandle.read(bufreadlen)
      for c in frequencies:
          frequencies[c] = float(frequencies[c]) / filesize
      ent = 0.0
      for frequency in frequencies.values():
          ent = ent + frequency * math.log(frequency, 2)
      ent = -ent
      return ent
  
  
  if __name__ == '__main__':
      parser = argparse.ArgumentParser()
      parser.add_argument('files', metavar='FILE', nargs='*')
      args = parser.parse_args()
      for f in args.files:
          print(entropy(f), f)
  