C++: Py_CompileString crash

K

KillSwitch

I run this code in VC++:

#include <Python.h>
#include <string.h>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
Py_Initialize();

const char* filename = "asdf.py";

const char* str = "print('lol')";

Py_CompileString(str, filename, 0);

Py_Finalize();
system("PAUSE");
return 0;
}

On running, it immediately crashes.

I use PyRun_SimpleString and other high level stuff from the API with
no problem, but Py_CompileString is not working. I'm probably using it
wrong.

Any help is appreciated.
 
K

KillSwitch

KillSwitch said:
int main(int argc, char *argv[])
{
   Py_Initialize();
   const char* filename = "asdf.py";
   const char* str = "print('lol')";
   Py_CompileString(str, filename, 0);
   Py_Finalize();
   system("PAUSE");
   return 0;
}
On running, it immediately crashes.

0 is wrong here, seehttp://docs.python.org/c-api/veryhigh.html?highlight=py_compilestring...

Christian

Yeah that's what I needed, thank you very much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top