Advertisement
Terbaddo

[Lib Python] Hello World

Jul 21st, 2011
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include "Python.h"
  2.  
  3. PyObject *xyzzy_foo(PyObject *self, PyObject* args)
  4. {
  5.     return PyString_FromString("Hello, World !");
  6. }
  7.  
  8. int main(int argc, char **argv)
  9. {
  10.     Py_SetProgramName(argv[0]);
  11.     Py_Initialize();
  12.     PyImport_AddModule("xyzzy");
  13.     PyMethodDef xyzzy_methods[] = { {"foo", xyzzy_foo, METH_NOARGS, "Return the meaning of everything."}, {NULL, NULL} };
  14.     Py_InitModule("xyzzy", xyzzy_methods);
  15.     PySys_SetArgvEx(argc, argv, 0);
  16.  
  17.     PyRun_SimpleString("import xyzzy\n");
  18.     PyRun_SimpleString("print xyzzy.foo()\n");
  19.  
  20.     Py_Exit(0);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement