title: C/C++ embedding python module PIL, the python function want to return all pixel data, but i why can't?
body: <p>add c/c++ code embedding python. all problem is in c code, I don't known how to get the pixel value.</p>
  
  <p><em>python code:</em></p>
  
  <pre><code>import Image
  
  format = ""
  mode = ""
  size = ""
  data = list()
  
  def getImage(file):
      im = Image.open(file)
      global format
      global mode
      global size
      global data
      format = im.format
      mode = im.mode
      size = im.size
  
      width, height = im.size
  
      for x in range(0, height):
          for y in range(0, width):
              data.append(im.getpixel((x,y)))
      return None
  </code></pre>
  
  <p>in C/C++ code
  My get the data length is 0. Any problems of the two for loop?</p>
  
  <pre><code>void loadImage(char *file) {
      Image* img = NULL;
      Py_Initialize();
      if ( !Py_IsInitialized() ) {
          std::cerr&lt;&lt;"Python initalize failed.\n";
          return NULL;
      }
      PyRun_SimpleString("import sys");
      PyRun_SimpleString("sys.path.append('./')");
  
      PyObject *pName, *pModule, *pFunc, *pArgs;
      pName = PyString_FromString("loadImage");
      pModule = PyImport_Import(pName);
      Py_DECREF(pName);
      if ( !pModule ) {
          PyErr_Print();
          std::cerr&lt;&lt;"import loadImage module faild, please confirm where the file     'loadImage.py' is.\n";
          return NULL;
      }
      pFunc = PyObject_GetAttrString(pModule, "getImage");
      if ( !pFunc ) {
          PyErr_Print();
          std::cerr&lt;&lt;"Can't find method getImage in loadImage module.\n";
          return NULL;
      }
  
      pArgs = PyTuple_New(1);
      PyTuple_SetItem(pArgs, 0, Py_BuildValue("s", file));
      PyObject_CallObject(pFunc, pArgs);
  
      PyObject *pFormat, *pMode, *pSize, *pData, *pSeq, *pPixel;
  
      pFormat = PyObject_GetAttrString(pModule, "format"); 
  
      pMode = PyObject_GetAttrString(pModule, "mode");
  
      pSize = PyObject_GetAttrString(pModule, "size");
  
      if ( !PyTuple_Check(pSize) ) {
          std::cerr&lt;&lt;"pSize is not tupple object.\n";
          return NULL;
      }
  
      pData = PyObject_GetAttrString(pModule, "data");
      if ( !pData ) {
          std::cerr&lt;&lt;"pData is null.\n";
          return NULL;
      }
      if ( !PyList_Check(pData) ) {
          std::cerr&lt;&lt;"pData is not list object.\n";
          return NULL;
      }
  
      int n = PyList_GET_SIZE(pData);
      std::cerr&lt;&lt;n&lt;&lt;"\n";
  
      Py_DECREF(pData);
      Py_DECREF(pFunc);
      Py_DECREF(pModule);
      Py_DECREF(pArgs);
  
      std::cerr&lt;&lt;"Py_DECREF over.\n";
  }
  </code></pre>
  
  <p>I get the lenght of pData(is n) is 0.</p>