a.c 554 B

12345678910111213141516171819202122
  1. #define PY_SSIZE_T_CLEAN
  2. #include <Python.h>
  3. int
  4. main(int argc, char *argv[])
  5. {
  6. wchar_t *program = Py_DecodeLocale(argv[0], NULL);
  7. if (program == NULL) {
  8. fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
  9. exit(1);
  10. }
  11. Py_SetProgramName(program); /* optional but recommended */
  12. Py_Initialize();
  13. PyRun_SimpleString("from time import time,ctime\n"
  14. "print('Today is', ctime(time()))\n");
  15. if (Py_FinalizeEx() < 0) {
  16. exit(120);
  17. }
  18. PyMem_RawFree(program);
  19. return 0;
  20. }