new_contents: """Image."""
  
  from PIL import Image
  import os
  
  
  class DatabaseImage(object):
  
      """Image from database."""
  
      def __init__(self, path):
          """Construct DatabaseImage."""
          self.path = path
          self.bmp = Image.open(path)
  
          filename = os.path.basename(path)
          self.id = int(filename.split('_')[0])
          self.sub_id = int(filename.split('_')[1])
  
      def __str__(self):
          """Return string representation of DatabaseImage."""
          return "{img.id:3} {img.sub_id}".format(img=self)
  
  
  def get_images():
      """Get images."""
      for root, directories, filenames in os.walk('database'):
          for filename in filenames:
              if filename.endswith('.gif'):
                  path = os.path.join(root, filename)
                  yield DatabaseImage(path)
  
  
  if __name__ == '__main__':
      for image in get_images():
          image.bmp.show()
          break
  
subject: Add DatabaseImage class