title: Python - AttributeError: __getitem__
body: <p>I am required to access all images in a folder and store it in a matrix using python. Here is my code.</p>
  
  <pre><code>import Image
  import os
  from PIL import Image
  from numpy import *
  import numpy as np
  
  
  #import images
  dirname = "C:\\Users\\Karim\\Downloads\\att_faces\\New folder"
  
  #get number of images and dimentions
  path, dirs, files = os.walk(dirname).next()
  num_images = len(files)
  image_file = "C:\\Users\\Karim\\Downloads\\att_faces\\New folder\\2.pgm"
  im = Image.open(image_file)
  width, height = im.size
  
  
  
  images = []
  
  for x in xrange(1, num_images):
      filename = os.listdir(dirname)[x]
      filepath = os.path.join(dirname, filename)
      img = Image.open(filepath)
      img = im.convert('L')
      images[:, x] = img[:]
  
  print images
  </code></pre>
  
  <p>but I am getting the error: <code>AttributeError: __getitem__</code> </p>
  
  <p>from the line: <code>images[:, x] = img[:]</code></p>