本文整理汇总了C++中PyRun_SimpleString函数的典型用法代码示例。如果您正苦于以下问题:C++ PyRun_SimpleString函数的具体用法?C++ PyRun_SimpleString怎么用?C++ PyRun_SimpleString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyRun_SimpleString函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: check_init
static void check_init() {
if ((initialized == 0) && ! Py_IsInitialized()) {
Py_Initialize();
#ifdef _WIN32
PyRun_SimpleString(pCleanPath);
#endif
initialized = 1;
}
}
开发者ID:AnneCarpenter,项目名称:python-javabridge,代码行数:9,代码来源:org_cellprofiler_javabridge_CPython.c
示例2: registerStdout
// Run a thread to manage a console-based interpreter
void ConsoleClass::pyconsole(){
std::string input, subinput;
bool outputting;
// Register python output to std streams
registerStdout(&std::cout);
registerStderr(&std::cerr);
while (true)
{
outputting = true;
// This could be replaced with pythons sys.ps1
std::cout << ">>> ";
// Reset stdin to deal with ctrl-c
// This needs actual handling later
std::cin.clear();
std::getline(std::cin, input);
// Handling for structures (if, while, def, etc)
if (input[input.length()-1] == ':')
{
outputting = false;
while (true)
{
// This could be replaced with pythons sys.ps2
std::cout << "... ";
std::getline(std::cin, subinput);
// When we get an empty line we are ready to run the input
if (subinput.length() == 0) break;
input += "\n" + subinput;
}
}
// TODO process ; delimited statements?
// Don't run empty input
if (input.length() == 0) continue;
// Aesthetics
input += "\n";
// Send to anyone listening for evaluated scripts
python_evaluator.Write(">>>" + input);
// These strings mean we won't get return/output, there are probably more
if (input.find("import") != std::string::npos) outputting = false;
if (input.find("print") != std::string::npos) outputting = false;
if (input.find("=") != std::string::npos) outputting = false;
// This is probably wrong
if (outputting)
input = "print " + input;
PyRun_SimpleString((char*)input.c_str());
}
}
开发者ID:pr0gr4mm3rr,项目名称:FreeBuild,代码行数:58,代码来源:PyConsole.cpp
示例3: main
int main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]); /* optional but recommended */
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print 'Today is',ctime(time())\n");
Py_Finalize();
return 0;
}
开发者ID:linearregression,项目名称:pam-typopw,代码行数:9,代码来源:c_2_python.c
示例4: main
int
main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]); /* optional but recommended */
Py_Initialize();
numargs = argc;
Py_InitModule("emb", EmbMethods);
PyRun_SimpleString("from time import time, ctime\n"
"print 'Today is', ctime(time())\n");
PyRun_SimpleString("import emb\n"
"print 'Number of arguments', emb.numargs()\n");
Py_Finalize();
return 0;
}
开发者ID:i-wind,项目名称:pymix,代码行数:18,代码来源:embed.c
示例5: python_check_error
void
python_check_error(void)
{
if (PyErr_Occurred()) {
PyErr_Print();
PyRun_SimpleString("import sys\nsys.stdout.flush()");
PyErr_Clear();
}
}
开发者ID:sizeofvoid,项目名称:profanity,代码行数:9,代码来源:python_plugins.c
示例6: script_init_mudmagic
PyMODINIT_FUNC script_init_mudmagic(void) {
PyObject * p_main;
PyImport_AddModule ("mudmagic");
Py_InitModule ("mudmagic", MudmagicMethods);
p_main = PyImport_AddModule ("__main__");
p_main_dict = PyModule_GetDict (p_main);
PyRun_SimpleString("from mudmagic import *\n");
}
开发者ID:dangardner,项目名称:mudmagic-client,代码行数:9,代码来源:script.c
示例7: PyRun_SimpleString
bool Pythonize::runString (char *str)
{
if (str == NULL || strlen (str) == 0) return false;
int res = PyRun_SimpleString (str);
return res == 0;
}
开发者ID:moceap,项目名称:scribus,代码行数:9,代码来源:pythonize.cpp
示例8: main
int main(int argc, char **argv) {
Py_SetProgramName(argv[0]); /* optional but recommended */
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print 'Today is',ctime(time())\n");
// or use PyRun_SimpleFile(FILE *fp, const char *filename) to run a program file
Py_Finalize();
return 0;
}
开发者ID:AhmedBoustani,项目名称:Utils,代码行数:9,代码来源:Python_in_C.c
示例9: PyRun_SimpleString
void PyModule::printInfo() {
for (auto& elem : methods_) {
std::string msg = "print(\"";
msg += elem->getName() + ":\t";
msg += elem->getDesc();
msg += "\")\n";
PyRun_SimpleString(msg.c_str());
}
}
开发者ID:Ojaswi,项目名称:inviwo,代码行数:9,代码来源:pymodule.cpp
示例10: init_script
void init_script(const char *exe_path)
{
exe_dir=QFileInfo(exe_path).absoluteDir();
qDebug() << "prog name:" << exe_path;
Py_SetProgramName((char*)exe_path);
qDebug() << "init py...";
Py_Initialize();
qDebug() << "init py ok";
init_python_console();
init_sproxel_bindings();
pycon("exe path: %s", exe_path);
pycon("exe dir: %s", exe_dir.absolutePath().toLocal8Bit().data());
QString code="import sys\nsys.path.insert(0, \"";
code.append(exe_dir.absolutePath());
code.append("\")\nprint 'sys.path:', sys.path\n");
PyRun_SimpleString(code.toLocal8Bit().data());
PyObject *mod=PyImport_ImportModule("sproxel_utils");
if (!mod)
{
PyErr_Print();
QMessageBox::critical(NULL, "Sproxel Error", "Failed to import sproxel_utils");
}
else
{
// check required methods
bool gotErrors=false;
py_save_project=PyObject_GetAttrString(mod, "save_project");
if (PyErr_Occurred()) { PyErr_Print(); gotErrors=true; }
py_load_project=PyObject_GetAttrString(mod, "load_project");
if (PyErr_Occurred()) { PyErr_Print(); gotErrors=true; }
py_init_plugin_pathes=PyObject_GetAttrString(mod, "init_plugin_pathes");
if (PyErr_Occurred()) { PyErr_Print(); gotErrors=true; }
py_scan_plugins=PyObject_GetAttrString(mod, "scan_plugins");
if (PyErr_Occurred()) { PyErr_Print(); gotErrors=true; }
py_register_plugins=PyObject_GetAttrString(mod, "register_plugins");
if (PyErr_Occurred()) { PyErr_Print(); gotErrors=true; }
py_unregister_plugins=PyObject_GetAttrString(mod, "unregister_plugins");
if (PyErr_Occurred()) { PyErr_Print(); gotErrors=true; }
pycon("Scripted methods: %s", gotErrors ? "some missing" : "all OK");
if (gotErrors) QMessageBox::critical(NULL, "Sproxel Error", "Some scripted methods are missing.");
Py_DECREF(mod); mod=NULL;
}
}
开发者ID:Nvveen,项目名称:sproxel,代码行数:57,代码来源:script.cpp
示例11: Python_Init
static int
Python_Init(void)
{
if (!initialised)
{
#ifdef DYNAMIC_PYTHON
if (!python_enabled(TRUE))
{
EMSG(_("E263: Sorry, this command is disabled, the Python library could not be loaded."));
goto fail;
}
#endif
init_structs();
#if !defined(MACOS) || defined(MACOS_X_UNIX)
Py_Initialize();
#else
PyMac_Initialize();
#endif
/* initialise threads */
PyEval_InitThreads();
#ifdef DYNAMIC_PYTHON
get_exceptions();
#endif
if (PythonIO_Init())
goto fail;
if (PythonMod_Init())
goto fail;
/* Remove the element from sys.path that was added because of our
* argv[0] value in PythonMod_Init(). Previously we used an empty
* string, but dependinding on the OS we then get an empty entry or
* the current directory in sys.path. */
PyRun_SimpleString("import sys; sys.path = filter(lambda x: x != '/must>not&exist', sys.path)");
/* the first python thread is vim's, release the lock */
Python_SaveThread();
initialised = 1;
}
return 0;
fail:
/* We call PythonIO_Flush() here to print any Python errors.
* This is OK, as it is possible to call this function even
* if PythonIO_Init() has not completed successfully (it will
* not do anything in this case).
*/
PythonIO_Flush();
return -1;
}
开发者ID:aosm,项目名称:vim,代码行数:56,代码来源:if_python.c
示例12: OllyPython_Init
BOOL OllyPython_Init(void)
{
char initfile[MAX_PATH];
char tmp[MAX_PATH+16];
BOOL result = 1;
if (initialized == 1)
{
return TRUE;
}
Addtolist(0, 0, "OllyPython");
result &= CheckFile("init.py");
result &= CheckFile("ollyapi.py");
result &= CheckFile("ollyutils.py");
if (!result)
{
Addtolist(0, -1, " Could not locate Python scripts");
return FALSE;
}
Py_Initialize();
if (!Py_IsInitialized())
{
Addtolist(0, -1, " Could not initialize Python");
return FALSE;
}
init_ollyapi();
GetModuleFileName(hinst, initfile, MAX_PATH);
PathRemoveFileSpec(initfile);
strncat(initfile, "\\python", 7);
snprintf(tmp, MAX_PATH+16, "OLLYPYTHON_PATH=\"%s\"", initfile);
PyRun_SimpleString(tmp);
strncat(initfile, "\\init.py", 8);
if (!ExecFile(initfile))
{
Addtolist(0, -1, " Could not run init.py");
return FALSE;
}
#ifdef ENABLE_PYTHON_PROFILING
PyEval_SetTrace(tracefunc, NULL);
#endif
initialized = 1;
return TRUE;
}
开发者ID:ur4ltz,项目名称:ollypython,代码行数:56,代码来源:ollypython.c
示例13: main
int main() {
PyObject *globals, *foo, *bar, *noargs, *ret;
Py_Initialize();
PyRun_SimpleString(
"def foo(): \n"
" return 2, 10 \n"
"def bar(): \n"
" return \n"
"def teste(a,b): \n"
" print a, b \n"
" return 42 \n"
);
globals = PyModule_GetDict(PyImport_AddModule("__main__"));
Py_INCREF(globals);
static PyMethodDef teste_def[] = {{ "teste", (PyCFunction) teste, METH_VARARGS, NULL }};
PyObject* teste_obj = Py_FindMethod(teste_def, NULL, "teste");
PyDict_SetItemString(globals, "teste", teste_obj);
PyObject *teste = PyDict_GetItemString(globals, "teste");
PyObject *obj_result = PyObject_CallFunction(teste, "si", "entrada", 2);
if (!obj_result) {
return;
}
long result = PyInt_AsLong(obj_result);
Py_DECREF(obj_result);
printf("teste returned %ld \n", result);
foo = PyDict_GetItemString(globals, "foo");
noargs = PyTuple_New(0);
ret = PyObject_Call(foo, noargs, NULL);
printf("foo returned (%d, %d)\n", PyInt_AsLong(PyTuple_GET_ITEM(ret, 0)),
PyInt_AsLong(PyTuple_GET_ITEM(ret, 1)));
bar = PyDict_GetItemString(globals, "bar");
Py_DECREF(ret);
ret = PyObject_Call(bar, noargs, NULL);
if (ret == Py_None) printf("bar returned Py_None\n");
Py_DECREF(ret);
Py_DECREF(noargs);
Py_DECREF(globals);
PyObject* s = PyString_FromString("hello world");
PyObject* split = PyObject_GetAttrString(s, "split");
ret = PyObject_CallFunction(split, "s", " ");
/*
ret = PyObject_CallMethod(s, "split", "s", " ");
*/
int i;
for (i = 0; i < PyList_GET_SIZE(ret); i++) {
PyObject* item = PyList_GetItem(ret, i);
printf("%d: '%s'\n", i, PyString_AsString(item));
}
Py_Finalize();
}
开发者ID:KarimTarabishy,项目名称:libscript,代码行数:56,代码来源:pythoncall.c
示例14: PyRun_SimpleString
void Python_group_script::execute(const std::string grid_name, const std::string group_name) const
{
PyRun_SimpleString(""
"import redirect\n"
"class CoutLogger:\n"
" def __init__(self):\n"
" self.buf = []\n"
" def write(self, data):\n"
" self.buf.append(data)\n"
" if data.endswith('\\n'):\n"
" redirect.sgems_cout(''.join(self.buf))\n"
" self.buf = []\n"
"\n"
"class CerrLogger:\n"
" def __init__(self):\n"
" self.buf = []\n"
" def write(self, data):\n"
" self.buf.append(data)\n"
" if data.endswith('\\n'):\n"
" redirect.sgems_cerr(''.join(self.buf))\n"
" self.buf = []\n"
"\n"
"import sys\n"
"sys.stdout = CoutLogger()\n"
"sys.stderr = CerrLogger()\n"
"");
FILE* fp = fopen(filename_.c_str(), "r");
if (!fp)
{
GsTLcerr << "can't open file " << filename_ << gstlIO::end;
return;
}
PyObject* module = PyImport_AddModule("__main__");
PyObject* dictionary = PyModule_GetDict(module);
PyObject* dictionary_copy = PyDict_Copy(dictionary);
PyRun_File(fp, filename_.c_str(), Py_file_input, dictionary_copy, dictionary_copy);
PyObject* function = PyDict_GetItemString(dictionary_copy, "sgems_execute_group_action");
if (PyCallable_Check(function))
{
PyObject* result = PyObject_CallFunction(function, "ss", grid_name.c_str(), group_name.c_str());
// if (NULL == result)
// {
// std::cout << "execution failed\n";
// }
Py_XDECREF(result);
}
Py_XDECREF(dictionary_copy);
fclose(fp);
}
开发者ID:TUDz,项目名称:ar2tech-SGeMS-public,代码行数:56,代码来源:python_group_script.cpp
示例15: test
void test() {
print_line("testing python");
PyRun_SimpleString("import engine\n");
PyRun_SimpleString("def test(self):\n\tprint(\"noway\")\n");
PyRun_SimpleString("a=engine.ObjectPtr()\n");
PyRun_SimpleString("a.noway(22,'hello')\n");
PyRun_SimpleString("a.normalize()\n");
PyRun_SimpleString("class Moch(engine.ObjectPtr):\n\tdef mooch(self):\n\t\tprint('muchi')\n");
PyRun_SimpleString("b=Moch();\n");
PyRun_SimpleString("b.mooch();\n");
PyRun_SimpleString("b.meis();\n");
}
开发者ID:Scrik,项目名称:godot,代码行数:15,代码来源:test_python.cpp
示例16: PyRun_SimpleString
std::string TCP2::getMessage() {
std::string s;
PyRun_SimpleString("d = open('storage_tcp2.txt','w')\n"
"d.write(s2.recv(1024))\n"
"d.close()\n");
std::ifstream infile;
infile.open("storage_tcp2.txt");
getline(infile, s);
return s;
}
开发者ID:RochauD,项目名称:JGameHack,代码行数:10,代码来源:TCP2.cpp
示例17: AddToSysPath
//---------------------------------------------------------------------------------
// Adds a path to sys.path (relative to GetSourcePythonDir()).
//---------------------------------------------------------------------------------
void AddToSysPath( const char* path )
{
char szFolderPath[MAX_PATH_LENGTH];
V_snprintf(szFolderPath, MAX_PATH_LENGTH, "%s%s", GetSourcePythonDir(), path);
V_FixSlashes(szFolderPath);
DevMsg(1, MSG_PREFIX "Adding %s to path\n", szFolderPath);
std::string szCommandString = "sys.path.append(r\"" + std::string(szFolderPath) + "\")";
PyRun_SimpleString(szCommandString.c_str());
}
开发者ID:ThaPwned,项目名称:Source.Python,代码行数:13,代码来源:sp_python.cpp
示例18: AddToSysPath
//---------------------------------------------------------------------------------
// Adds a path to sys.path (relative to g_GamePaths.GetSPDir()).
//---------------------------------------------------------------------------------
void AddToSysPath( const char* path )
{
char szFolderPath[MAX_GAME_PATH];
V_snprintf(szFolderPath, MAX_GAME_PATH, "%s%s", g_GamePaths.GetSPDir(), path);
V_FixSlashes(szFolderPath);
DevMsg(1, "[SP] Adding %s to path\n", szFolderPath);
std::string szCommandString = "sys.path.append(r\"" + std::string(szFolderPath) + "\")";
PyRun_SimpleString(szCommandString.c_str());
}
开发者ID:MrMalina,项目名称:Source.Python,代码行数:13,代码来源:sp_python.cpp
示例19: vette_assertInitialized
void vette_assertInitialized() {
if( !Py_IsInitialized() ) {
Py_Initialize();
}
if( !vette_IsLoaded ) {
if( elDEBUG ) printf( "PYTHON CALL: import vette\n" );
PyRun_SimpleString( (char*)"import vette" );
vette_IsLoaded = 1;
}
}
开发者ID:PlamenStilyianov,项目名称:Python,代码行数:10,代码来源:vette.c
示例20: clPyGlueInit
void clPyGlueInit(char* appModule,void (*init_extensions[])(void),int argc, char**argv)
{
char buf[1024];
ClRcT rc;
Py_Initialize();
PySys_SetArgv(argc, argv);
PyEval_InitThreads();
if (init_extensions)
{
int i = 0;
for(i=0; init_extensions[i]!=NULL; i++) (*init_extensions[i])();
}
thrdState = PyThreadState_Get();
rc = clOsalMutexInit(&pyMutex);
CL_ASSERT(rc==CL_OK);
rc = clOsalCondInit(&event);
CL_ASSERT(rc==CL_OK);
rc = clOsalMutexLock(&pyMutex);
CL_ASSERT(rc==CL_OK);
PyThreadState_Swap(thrdState);
PyRun_SimpleString("import os, os.path, sys\n");
snprintf(buf,1024,"sys.path.append(os.path.realpath('%s'))\n",CL_APP_BINDIR);
clprintf(CL_LOG_SEV_INFO, buf);
PyRun_SimpleString(buf);
//PyRun_SimpleString("sys.path.append(os.path.realpath('../../bin'))\n");
snprintf(buf,1024,"from %s import *\n",appModule);
clprintf(CL_LOG_SEV_INFO, buf);
PyRun_SimpleString(buf);
PyThreadState_Swap(NULL);
PyEval_ReleaseLock();
rc=clOsalMutexUnlock(&pyMutex);
CL_ASSERT(rc==CL_OK);
}
开发者ID:joaohf,项目名称:SAFplus-Availability-Scalability-Platform,代码行数:42,代码来源:pyglue.c
注:本文中的PyRun_SimpleString函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论