本文整理汇总了C++中Py_SetProgramName函数的典型用法代码示例。如果您正苦于以下问题:C++ Py_SetProgramName函数的具体用法?C++ Py_SetProgramName怎么用?C++ Py_SetProgramName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Py_SetProgramName函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ada_py_initialize_and_module
PyObject*
ada_py_initialize_and_module(char* program_name, char* name) {
PyObject* module;
PyObject* imported;
user_module_name = strdup(name);
#if PY_MAJOR_VERSION >= 3
user_module.m_name = user_module_name;
Py_SetProgramName ((wchar_t*)program_name);
#else
Py_SetProgramName (program_name);
#endif
PyImport_AppendInittab(user_module_name, init_user_module);
Py_InitializeEx(0);
// Initialize the prompt if needed
PyObject* prompt = PySys_GetObject ("ps1");
if (prompt == NULL) {
prompt = PyUnicode_FromString (">>> ");
PySys_SetObject ("ps1", prompt);
Py_DECREF (prompt);
}
prompt = PySys_GetObject ("ps2");
if (prompt == NULL) {
prompt = PyUnicode_FromString ("... ");
PySys_SetObject ("ps2", prompt);
Py_DECREF (prompt);
}
// Make the user's module visible to scripts. We cannot use
// PyImport_ImportModule, which imports the module but doesn't add
// it to the global dictionary and as such it is not visible to
// user scripts.
imported = PyImport_ImportModule(name);
if (imported == NULL) {
printf ("Could not import module %s", name);
return NULL;
}
// Import 'sys', which is needed for instance in Set_Default_Console
// to get access to the default value
PyRun_SimpleString("import sys\n");
char* command = (char*)malloc(9 + strlen(name));
strcpy (command, "import ");
strcat (command, name);
strcat (command, "\n");
PyRun_SimpleString(command);
free (command);
return imported;
};
开发者ID:cbourgeois,项目名称:gnatcoll,代码行数:57,代码来源:python_support.c
示例2: LogInfo
void PyInviwo::initPythonCInterface(Python3Module* module) {
if (isInit_) return;
isInit_ = true;
LogInfo("Python version: " + toString(Py_GetVersion()));
wchar_t programName[] = L"PyInviwo";
Py_SetProgramName(programName);
Py_InitializeEx(false);
if (!Py_IsInitialized()) {
LogError("Python is not Initialized");
return;
}
PyEval_InitThreads();
importModule("builtins");
importModule("sys");
dict_ = PyImport_GetModuleDict();
registerPyModule(&Inviwo_Internals_Module_Def, "inviwo_internal");
registerPyModule(&Inviwo_Module_Def, "inviwo");
addModulePath(module->getPath() + "/scripts");
initOutputRedirector(module);
}
开发者ID:ResearchDaniel,项目名称:inviwo,代码行数:26,代码来源:pyinviwo.cpp
示例3: do_pyinit
void do_pyinit() {
#ifdef EXPOSE_PERL
PyObject *main_dict;
PyObject *perl_obj;
PyObject *dummy1 = PyString_FromString(""),
*dummy2 = PyString_FromString("main");
#endif
/* sometimes Python needs to know about argc and argv to be happy */
int _python_argc = 1;
char *_python_argv[] = {
"python",
};
Py_SetProgramName("python");
Py_Initialize();
PySys_SetArgv(_python_argc, _python_argv); /* Tk needs this */
#ifdef EXPOSE_PERL
/* create the perl module and add functions */
initperl();
/* now -- create the main 'perl' object and add it to the dictionary. */
perl_obj = newPerlPkg_object(dummy1,dummy2);
main_dict = PyModule_GetDict(PyImport_AddModule("__main__"));
PyDict_SetItemString(main_dict, "perl", perl_obj);
Py_DECREF(perl_obj);
Py_DECREF(dummy1);
Py_DECREF(dummy2);
#endif
}
开发者ID:carriercomm,项目名称:MyProject,代码行数:32,代码来源:Python.c
示例4: XOJ_CHECK_TYPE
void PythonRunner::initPython() {
XOJ_CHECK_TYPE(PythonRunner);
if (this->pythonInitialized) {
return;
}
Py_SetProgramName("Xournal");
Py_Initialize();
PyXournal_initPython(this->control);
char buffer[512] = { 0 };
const char * path = getcwd(buffer, sizeof(buffer));
g_return_if_fail(path != NULL);
PyObject * sysModule = PyImport_ImportModule("sys");
g_return_if_fail(sysModule != NULL);
PyObject * pathObject = PyObject_GetAttrString(sysModule, "path");
g_return_if_fail(pathObject != NULL);
String p = path;
p += "/../testing";
PyObject * ret = PyObject_CallMethod(pathObject, "append", "s", p.c_str());
Py_DecRef(ret);
p = path;
p += "/testing";
ret = PyObject_CallMethod(pathObject, "append", "s", p.c_str());
Py_DecRef(ret);
Py_DecRef(pathObject);
Py_DecRef(sysModule);
}
开发者ID:wbrenna,项目名称:xournalpp,代码行数:34,代码来源:PythonRunner.cpp
示例5: embed_init_python
void embed_init_python(void)
{
FENTER;
#ifndef PYTHON_SO_LIB
#error "Python version needs passing in with -DPYTHON_SO_VERSION=libpython<ver>.so"
#else
#define PY_SO_LIB xstr(PYTHON_SO_LIB)
#endif
void *ret = dlopen(PY_SO_LIB, RTLD_LAZY | RTLD_GLOBAL);
if (!ret) {
fprintf(stderr, "Failed to find python lib %s (%s)\n", PY_SO_LIB, dlerror());
}
// Don't initialise python if already running
if (gtstate)
return;
Py_SetProgramName(progname);
Py_Initialize(); /* Initialize the interpreter */
PySys_SetArgvEx(1, argv, 0);
PyEval_InitThreads(); /* Create (and acquire) the interpreter lock */
/* Swap out and return current thread state and release the GIL */
gtstate = PyEval_SaveThread();
FEXIT;
}
开发者ID:FinnG,项目名称:cocotb,代码行数:28,代码来源:gpi_embed.c
示例6: _testembed_Py_Initialize
static void _testembed_Py_Initialize(void)
{
/* HACK: the "./" at front avoids a search along the PATH in
Modules/getpath.c */
Py_SetProgramName(L"./_testembed");
Py_Initialize();
}
开发者ID:1st1,项目名称:cpython,代码行数:7,代码来源:_testembed.c
示例7: mod_init
static int mod_init(rlm_python_t *inst)
{
int i;
static char name[] = "radiusd";
if (radiusd_module) return 0;
/*
* Explicitly load libpython, so symbols will be available to lib-dynload modules
*/
inst->libpython = dlopen("libpython" STRINGIFY(PY_MAJOR_VERSION) "." STRINGIFY(PY_MINOR_VERSION) ".so",
RTLD_NOW | RTLD_GLOBAL);
if (!inst->libpython) {
WARN("Failed loading libpython symbols into global symbol table: %s", dlerror());
}
Py_SetProgramName(name);
#ifdef HAVE_PTHREAD_H
Py_InitializeEx(0); /* Don't override signal handlers */
PyEval_InitThreads(); /* This also grabs a lock */
inst->main_thread_state = PyThreadState_Get(); /* We need this for setting up thread local stuff */
#endif
if (inst->python_path) {
PySys_SetPath(inst->python_path);
}
if ((radiusd_module = Py_InitModule3("radiusd", radiusd_methods,
"FreeRADIUS Module.")) == NULL)
goto failed;
for (i = 0; radiusd_constants[i].name; i++) {
if ((PyModule_AddIntConstant(radiusd_module, radiusd_constants[i].name,
radiusd_constants[i].value)) < 0) {
goto failed;
}
}
#ifdef HAVE_PTHREAD_H
PyThreadState_Swap(NULL); /* We have to swap out the current thread else we get deadlocks */
PyEval_ReleaseLock(); /* Drop lock grabbed by InitThreads */
#endif
DEBUG("mod_init done");
return 0;
failed:
Py_XDECREF(radiusd_module);
#ifdef HAVE_PTHREAD_H
PyEval_ReleaseLock();
#endif
Pyx_BLOCK_THREADS
mod_error();
Pyx_UNBLOCK_THREADS
radiusd_module = NULL;
Py_Finalize();
return -1;
}
开发者ID:padam,项目名称:freeradius-server,代码行数:60,代码来源:rlm_python.c
示例8: main
int main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]);
Py_Initialize();
initschoolboy_rsa();
return 0;
}
开发者ID:pbsphp,项目名称:schoolboy_rsa,代码行数:7,代码来源:python_extension.c
示例9: freopen
Pyramid::Pyramid(const char* script)
{
freopen("pyramid.log", "w", stdout);
freopen("pyramid.log", "a", stderr);
Py_SetProgramName(".\\pyramid");
Py_Initialize();
init_pyramid();
PyRun_SimpleString(
"import sys\n"
"sys.path.append('./')\n"
"sys.stderr = open('python_errors.log', 'w', 0)\n"
"sys.stdout = open('pyramid.log', 'a', 0)\n"
"import pyramid\n");
char* fn_local = new char[strlen(script)+1];
strcpy(fn_local, script);
PyObject* fp = PyFile_FromString(fn_local, "r");
if(!fp)
{
printf("Could not load mapping script '%s' for reading.\n", script);
Py_Finalize();
exit(1);
}
FILE* sfp = PyFile_AsFile(fp);
PyRun_AnyFileEx(sfp, script, 1);
delete[] fn_local;
}
开发者ID:m4burns,项目名称:pyramid,代码行数:31,代码来源:Pyramid.cpp
示例10: python_system_init
/* Initialize Python interpreter */
static void python_system_init(lua_State *L) {
char *python_home = luaL_check_string(L, 1);
if (!Py_IsInitialized()) {
python_setnumber(L, PY_API_IS_EMBEDDED, 1); // If python is inside Lua
if (PyType_Ready(&LuaObject_Type) == 0) {
Py_INCREF(&LuaObject_Type);
} else {
lua_error(L, "failure initializing lua object type");
}
PyObject *luam, *mainm, *maind;
#if PY_MAJOR_VERSION >= 3
wchar_t *argv[] = {L"<lua_bootstrap>", 0};
#else
char *argv[] = {"<lua_bootstrap>", 0};
#endif
Py_SetProgramName(argv[0]);
Py_SetPythonHome(python_home);
Py_InitializeEx(0);
PySys_SetArgv(1, argv);
/* Import 'lua' automatically. */
luam = PyImport_ImportModule("lua_bootstrap");
if (!luam) {
lua_error(L, "Can't import lua_bootstrap module");
} else {
mainm = PyImport_AddModule("__main__");
if (!mainm) {
lua_error(L, "Can't get __main__ module");
} else {
maind = PyModule_GetDict(mainm);
PyDict_SetItemString(maind, "lua_bootstrap", luam);
Py_DECREF(luam);
}
}
}
}
开发者ID:alexsilva,项目名称:lunatic-python,代码行数:36,代码来源:pythoninlua.c
示例11: rpmpythonNew
rpmpython rpmpythonNew(char ** av, uint32_t flags)
{
static char * _av[] = { "rpmpython", NULL };
#if defined(WITH_PYTHONEMBED)
int initialize = (!(flags & 0x80000000) || _rpmpythonI == NULL);
#endif
rpmpython python = (flags & 0x80000000)
? rpmpythonI() : rpmpythonGetPool(_rpmpythonPool);
if (_rpmpython_debug)
fprintf(stderr, "==> %s(%p, %d) python %p\n", __FUNCTION__, av, flags, python);
if (av == NULL) av = _av;
#if defined(WITH_PYTHONEMBED)
if (!Py_IsInitialized()) {
Py_SetProgramName((char *)_av[0]);
Py_Initialize();
}
if (PycStringIO == NULL)
PycStringIO = PyCObject_Import("cStringIO", "cStringIO_CAPI");
if (initialize) {
int ac = argvCount((ARGV_t)av);
(void) PySys_SetArgv(ac, (char **)av);
(void) rpmpythonRun(python, rpmpythonInitStringIO, NULL);
}
#endif
return rpmpythonLink(python);
}
开发者ID:hahnakane,项目名称:junkcode,代码行数:31,代码来源:rpmpython.c
示例12: main
int main(int argc, char **argv)
{
#if (COW_MPI)
{
int rank;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank != 0) freopen("/dev/null", "w", stdout);
printf("was compiled with MPI support\n");
}
#endif
Py_Initialize();
PySys_SetArgv(argc, argv);
Py_SetProgramName("/Users/jzrake/Work/cow/cowpy");
init_cow();
if (argc > 1) {
FILE *fp = fopen(argv[1], "r");
if (fp) {
PyRun_SimpleFileExFlags(fp, argv[1], 1, NULL);
fclose(fp);
}
else {
printf("No such file %s\n", argv[1]);
}
}
Py_Finalize();
printf("finished...\n");
#if (COW_MPI)
MPI_Finalize();
#endif
return 0;
}
开发者ID:darien0,项目名称:cow,代码行数:34,代码来源:cowpy.c
示例13: main
int main(int argc, char *argv[]) {
// Set the python interpreter.
setup_python(argc, argv);
std::string filepath(argv[0]);
// Get the path to the helper script.
std::string helper_path;
size_t path_end = filepath.find_last_of('\\');
if (path_end != std::string::npos)
helper_path = filepath.substr(0, path_end + 1);
helper_path += "wbadminhelper.py";
// Configures the execution of the script to take the same
// parameters as this helper tool.
Py_SetProgramName(argv[0]);
PySys_SetArgv(argc, argv);
// Executes the helper script.
PyObject *pFileObject = PyFile_FromString(const_cast<char *>(helper_path.c_str()), "r");
PyRun_SimpleFileEx(PyFile_AsFile(pFileObject), "wbadminhelper.py", 1);
finalize_python();
return 0;
}
开发者ID:pk-codebox-evo,项目名称:mysql-workbench,代码行数:29,代码来源:admin_helper.cpp
示例14: main
int
main(int argc, char **argv)
{
PyObject *main, *game;
PyObject *func, *args;
PyTaskletObject *process;
Py_SetProgramName(argv[0]);
Py_Initialize();
/* get the time python methods */
timemod = PyImport_ImportModule("time");
/* create a module for the game */
game = Py_InitModule("game", game_methods);
/* run the definition in main module */
main = PyImport_AddModule("__main__");
PyRun_SimpleString(python_prog); /* runs in main */
/* start the python function as a tasklet */
func = PyObject_GetAttrString(main, "everySecond");
process = PyTasklet_New(NULL, func);
Py_DECREF(func);
/* initialize the tasklet args */
args = PyTuple_New(0);
PyTasklet_Setup(process, args, NULL);
Py_DECREF(args);
/* now let's run the "game engine" */
run_game_engine();
Py_Finalize();
return 0;
}
开发者ID:breezechen,项目名称:stacklessexamples,代码行数:30,代码来源:dice1.c
示例15: main
int main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]);
Py_Initialize();
initacc_monitor();
return 1;
}
开发者ID:xiansl,项目名称:mytests,代码行数:7,代码来源:acc_monitor.c
示例16: LogInfo
void PyInviwo::initPythonCInterface() {
if (isInit_) return;
isInit_ = true;
LogInfo("Python version: " + toString(Py_GetVersion()));
wchar_t programName[] = L"PyInviwo";
Py_SetProgramName(programName);
#ifdef WIN32
Py_NoSiteFlag = 1;
#endif
Py_InitializeEx(false);
if (!Py_IsInitialized()) {
LogError("Python is not Initialized");
return;
}
PyEval_InitThreads();
mainDict_ = PyDict_New();
modulesDict_ = PyImport_GetModuleDict();
importModule("builtins");
importModule("sys");
importModule("os");
importModule("glob");
importModule("random");
addModulePath(InviwoApplication::getPtr()->getBasePath() + "/modules/python3/scripts");
initDefaultInterfaces();
initOutputRedirector();
}
开发者ID:sarbi127,项目名称:inviwo,代码行数:33,代码来源:pyinviwo.cpp
示例17: main
int
main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]);
Py_Initialize();
initfirstmodule();
}
开发者ID:awhawks,项目名称:stiq,代码行数:7,代码来源:firstmodule.c
示例18: main
int main(int argc, char *argv[]) {
int ret = 0;
/* Must be the first thing we do to get everything else started
* We can do this here even though Py_Main will call those again.
* However, we must run them before creating our sub-interpreter.
*
* See comments on ARGV0 as to why we set it like this.
*/
Py_SetProgramName(ARGV0);
Py_Initialize();
/* Create sub-interpreter */
#ifdef DEBUG
fprintf(stderr, "starting new interpreter\n");
#endif
shd_py_interpreter = Py_NewInterpreter();
if(!shd_py_interpreter) {
PyErr_Print();
return 1;
}
PyThreadState *old = PyThreadState_Swap(shd_py_interpreter);
ret = python_main(argc, argv);
#ifdef DEBUG
fprintf(stderr, "shutting down interpreter\n");
#endif
PyThreadState_Swap(shd_py_interpreter);
Py_EndInterpreter(shd_py_interpreter);
shd_py_interpreter = NULL;
PyThreadState_Swap(old);
Py_Finalize();
return ret;
#undef PYERR
}
开发者ID:shadow,项目名称:shadow-plugin-extras,代码行数:34,代码来源:python.c
示例19: import_call_execute
/** This imports a Python module and calls a specific function in it.
* It's arguments are similar to main():
* argc - Number of strings in argv
* argv - Expected to be 4 strings:
* - Name of the executable.
* - Path to the directory that the Python module is in.
* - Name of the Python module.
* - Name of the function in the module.
*
* The Python interpreter will be initialised and the path to the Python module
* will be added to sys.paths then the module will be imported.
* The function will be called with no arguments and its return value will be
* ignored.
*
* This returns 0 on success, non-zero on failure.
*/
int import_call_execute(int argc, const char *argv[]) {
int return_value = 0;
PyObject *pModule = NULL;
PyObject *pFunc = NULL;
PyObject *pResult = NULL;
if (argc != 4) {
fprintf(stderr,
"Wrong arguments!"
" Usage: %s package_path module function\n", argv[0]);
return_value = -1;
goto except;
}
Py_SetProgramName((wchar_t*)argv[0]);
Py_Initialize();
if (add_path_to_sys_module(argv[1])) {
return_value = -2;
goto except;
}
pModule = PyImport_ImportModule(argv[2]);
if (! pModule) {
fprintf(stderr,
"%s: Failed to load module \"%s\"\n", argv[0], argv[2]);
return_value = -3;
goto except;
}
pFunc = PyObject_GetAttrString(pModule, argv[3]);
if (! pFunc) {
fprintf(stderr,
"%s: Can not find function \"%s\"\n", argv[0], argv[3]);
return_value = -4;
goto except;
}
if (! PyCallable_Check(pFunc)) {
fprintf(stderr,
"%s: Function \"%s\" is not callable\n", argv[0], argv[3]);
return_value = -5;
goto except;
}
pResult = PyObject_CallObject(pFunc, NULL);
if (! pResult) {
fprintf(stderr, "%s: Function call failed\n", argv[0]);
return_value = -6;
goto except;
}
#ifdef DEBUG
printf("%s: PyObject_CallObject() succeeded\n", argv[0]);
#endif
assert(! PyErr_Occurred());
goto finally;
except:
assert(PyErr_Occurred());
PyErr_Print();
finally:
Py_XDECREF(pFunc);
Py_XDECREF(pModule);
Py_XDECREF(pResult);
Py_Finalize();
return return_value;
}
开发者ID:mapillary,项目名称:OpenSfM,代码行数:76,代码来源:py_import_call_execute.c
示例20: main
int
main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]);
Py_Initialize();
initscsi();
}
开发者ID:DaveDaCoda,项目名称:PyBadUSB,代码行数:7,代码来源:scsi.cpp
注:本文中的Py_SetProgramName函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论