3
我該如何運行python數據,我用Python.h在內存中加載了?我正在使用包含已編譯的Python代碼的專有文件格式。從內存中運行pyc數據C
例如,我的代碼
FILE *fp;
long code_size;
char *code;
fp = fopen("file.format", "rb");
fread(&code_size, sizeof(long), 1, fp);
if (code_size > 0)
{
code = malloc(code_size);
/* the pyc data starts at offset 0x100 for example */
fseek(fp, 0x100, SEEK_SET);
/* read the pyc into the allocated memory */
fread(code, sizeof(char), code_size, fp);
/* execute the pyc data somehow using functions in Python.h.. */
}
fclose(fp);
[documentation](http://docs.python.org/extending/index.html)位於python站點上。 – 2012-01-19 00:29:37