• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PyImport_GetModuleDict函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中PyImport_GetModuleDict函数的典型用法代码示例。如果您正苦于以下问题:C++ PyImport_GetModuleDict函数的具体用法?C++ PyImport_GetModuleDict怎么用?C++ PyImport_GetModuleDict使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了PyImport_GetModuleDict函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: 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


示例2: AerospikeGeospatial_DoDumps

PyObject * AerospikeGeospatial_DoDumps(PyObject *geo_data, as_error *err)
{
    PyObject *initresult = NULL;

    PyObject* sysmodules = PyImport_GetModuleDict();
    PyObject* json_module = NULL;
	if (PyMapping_HasKeyString(sysmodules, "json")) {
        json_module = PyMapping_GetItemString(sysmodules, "json");
	} else {
	    json_module = PyImport_ImportModule("json");
    }

	if (!json_module) {
        /* insert error handling here! and exit this function */
		as_error_update(err, AEROSPIKE_ERR_CLIENT, "Unable to load json module");
	} else {
        PyObject *py_funcname = PyString_FromString("dumps");
        Py_INCREF(json_module);
        initresult = PyObject_CallMethodObjArgs(json_module, py_funcname, geo_data, NULL);
        Py_DECREF(json_module);
        Py_DECREF(py_funcname);
    }

    return initresult;
}
开发者ID:Kavec,项目名称:aerospike-client-python,代码行数:25,代码来源:dumps.c


示例3: 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


示例4: loadModule_

	PyObject* loadModule_(const QString& name)
	{
		PyObject* module_dict = PyImport_GetModuleDict();

		if(!module_dict)
		{
			Log.error() << "Could not obtain module dictionary" << std::endl;
			return 0;
		}

		PyObject* mod_name = PyString_FromString(name.toAscii().data());

		PyObject* module = 0;

		if(PyDict_Contains(module_dict, mod_name))
		{
			module = PyDict_GetItem(module_dict, mod_name);
		}
		else
		{
			//This could leak the imported module. Need to check...
			module = PyImport_ImportModule(name.toAscii().data());
		}

		Py_XDECREF(mod_name);


		if(!module || PyErr_Occurred())
		{
			PyErr_Print();
			return 0;
		}

		return module;
	}
开发者ID:HeyJJ,项目名称:ball,代码行数:35,代码来源:pyInterpreter.C


示例5: uninstall_py_dlls

bool uninstall_py_dlls(void)
{
	PyObject *modules = PyImport_GetModuleDict();
	int i = 0;

	while(true)
	{
		if(g_funs[i] == NULL)
			break;

		DEBUG_MSG(fmt::format("Script::uninstall_py_dlls(): {}\n", g_sfuns[i]));
		PyObject * m = g_importedModules[i++];
		if(m == NULL)
		{
			return false;
		}

		Py_DECREF(m);

		struct PyModuleDef *def;
		def = PyModule_GetDef(m);
		if (!def) {
			PyErr_BadInternalCall();
			return false;
		}

		if (PyState_RemoveModule(def) < 0 || PyDict_DelItemString(modules, def->m_name) < 0)
			return false;
	}

	return true;
}
开发者ID:Orav,项目名称:kbengine,代码行数:32,代码来源:install_py_dlls.cpp


示例6: PyInit_gpu

PyObject *GPU_initPython(void)
{
	PyObject *module = PyInit_gpu();
	PyModule_AddObject(module, "export_shader", (PyObject *)PyCFunction_New(meth_export_shader, NULL));
	PyDict_SetItemString(PyImport_GetModuleDict(), "gpu", module);

	return module;
}
开发者ID:244xiao,项目名称:blender,代码行数:8,代码来源:gpu.c


示例7: AUD_initPython

PyObject* AUD_initPython()
{
	PyObject* module = PyInit_aud();
	PyModule_AddObject(module, "device", (PyObject*)PyCFunction_New(meth_getcdevice, NULL));
	PyModule_AddObject(module, "_sound_from_pointer", (PyObject*)PyCFunction_New(meth_sound_from_pointer, NULL));
	PyDict_SetItemString(PyImport_GetModuleDict(), "aud", module);

	return module;
}
开发者ID:HVisionSensing,项目名称:blendocv,代码行数:9,代码来源:AUD_C-API.cpp


示例8: _PyImport_LoadDynamicModule

PyObject *
_PyImport_LoadDynamicModule(char *name, char *pathname, FILE *fp)
{
	PyObject *m, *d, *s;
	char *lastdot, *shortname, *packagecontext;
	dl_funcptr p;

	if ((m = _PyImport_FindExtension(name, pathname)) != NULL) {
		Py_INCREF(m);
		return m;
	}
	lastdot = strrchr(name, '.');
	if (lastdot == NULL) {
		packagecontext = NULL;
		shortname = name;
	}
	else {
		packagecontext = name;
		shortname = lastdot+1;
	}

	p = _PyImport_GetDynLoadFunc(name, shortname, pathname, fp);
	if (PyErr_Occurred())
		return NULL;
	if (p == NULL) {
		PyErr_Format(PyExc_ImportError,
		   "dynamic module does not define init function (init%.200s)",
			     shortname);
		return NULL;
	}
	_Py_PackageContext = packagecontext;
	(*p)();
	_Py_PackageContext = NULL;
	if (PyErr_Occurred())
		return NULL;
	if (_PyImport_FixupExtension(name, pathname) == NULL)
		return NULL;

	m = PyDict_GetItemString(PyImport_GetModuleDict(), name);
	if (m == NULL) {
		PyErr_SetString(PyExc_SystemError,
				"dynamic module not initialized properly");
		return NULL;
	}
	/* Remember the filename as the __file__ attribute */
	d = PyModule_GetDict(m);
	s = PyString_FromString(pathname);
	if (s == NULL || PyDict_SetItemString(d, "__file__", s) != 0)
		PyErr_Clear(); /* Not important enough to report */
	Py_XDECREF(s);
	if (Py_VerboseFlag)
		PySys_WriteStderr(
			"import %s # dynamically loaded from %s\n",
			name, pathname);
	Py_INCREF(m);
	return m;
}
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:57,代码来源:importdl.c


示例9: init

static PyObject*
init (PyObject* self)
{
    PyObject *allmodules, *moduleslist, *dict, *func, *result, *mod;
    int loop, num;
    int success=0, fail=0;

    if (!CheckSDLVersions ())
        return NULL;


    /*nice to initialize timer, so startup time will reflec init() time*/
    sdl_was_init = SDL_Init (
#if defined(WITH_THREAD) && !defined(MS_WIN32) && defined(SDL_INIT_EVENTTHREAD)
                       SDL_INIT_EVENTTHREAD |
#endif
                       SDL_INIT_TIMER |
                       SDL_INIT_NOPARACHUTE) == 0;


    /* initialize all pygame modules */
    allmodules = PyImport_GetModuleDict ();
    moduleslist = PyDict_Values (allmodules);
    if (!allmodules || !moduleslist)
        return Py_BuildValue ("(ii)", 0, 0);

    if (PyGame_Video_AutoInit ())
        ++success;
    else
        ++fail;

    num = PyList_Size (moduleslist);
    for (loop = 0; loop < num; ++loop)
    {
        mod = PyList_GET_ITEM (moduleslist, loop);
        if (!mod || !PyModule_Check (mod))
            continue;
        dict = PyModule_GetDict (mod);
        func = PyDict_GetItemString (dict, "__PYGAMEinit__");
        if(func && PyCallable_Check (func))
        {
            result = PyObject_CallObject (func, NULL);
            if (result && PyObject_IsTrue (result))
                ++success;
            else
            {
                PyErr_Clear ();
                ++fail;
            }
            Py_XDECREF (result);
        }
    }
    Py_DECREF (moduleslist);

    return Py_BuildValue ("(ii)", success, fail);
}
开发者ID:Mrhjx2,项目名称:pygame,代码行数:56,代码来源:base.c


示例10: import_init

static void
import_init(PyInterpreterState *interp, PyObject *sysmod)
{
    PyObject *importlib;
    PyObject *impmod;
    PyObject *sys_modules;
    PyObject *value;

    /* Import _importlib through its frozen version, _frozen_importlib. */
    if (PyImport_ImportFrozenModule("_frozen_importlib") <= 0) {
        Py_FatalError("Py_Initialize: can't import _frozen_importlib");
    }
    else if (Py_VerboseFlag) {
        PySys_FormatStderr("import _frozen_importlib # frozen\n");
    }
    importlib = PyImport_AddModule("_frozen_importlib");
    if (importlib == NULL) {
        Py_FatalError("Py_Initialize: couldn't get _frozen_importlib from "
                      "sys.modules");
    }
    interp->importlib = importlib;
    Py_INCREF(interp->importlib);

    interp->import_func = PyDict_GetItemString(interp->builtins, "__import__");
    if (interp->import_func == NULL)
        Py_FatalError("Py_Initialize: __import__ not found");
    Py_INCREF(interp->import_func);

    /* Import the _imp module */
    impmod = PyInit_imp();
    if (impmod == NULL) {
        Py_FatalError("Py_Initialize: can't import _imp");
    }
    else if (Py_VerboseFlag) {
        PySys_FormatStderr("import _imp # builtin\n");
    }
    sys_modules = PyImport_GetModuleDict();
    if (Py_VerboseFlag) {
        PySys_FormatStderr("import sys # builtin\n");
    }
    if (PyDict_SetItemString(sys_modules, "_imp", impmod) < 0) {
        Py_FatalError("Py_Initialize: can't save _imp to sys.modules");
    }

    /* Install importlib as the implementation of import */
    value = PyObject_CallMethod(importlib, "_install", "OO", sysmod, impmod);
    if (value == NULL) {
        PyErr_Print();
        Py_FatalError("Py_Initialize: importlib install failed");
    }
    Py_DECREF(value);
    Py_DECREF(impmod);

    _PyImportZip_Init();
}
开发者ID:yoongkang,项目名称:cpython,代码行数:55,代码来源:pylifecycle.c


示例11: PyPgFunction_RemoveModule

/*
 * Remove the function module from sys.modules
 *
 * >>> del sys.modules[func.oidstr]
 *
 * -1 on error.
 */
int
PyPgFunction_RemoveModule(PyObj func)
{
	int rv;
	PyObj modules;

	modules = PyImport_GetModuleDict();

	rv = PySequence_Contains(modules, PyPgFunction_GetPyUnicodeOid(func));
	if (rv == 1)
		rv = PyObject_DelItem(modules, PyPgFunction_GetPyUnicodeOid(func));

	return(rv);
}
开发者ID:fdr,项目名称:pg-python,代码行数:21,代码来源:function.c


示例12: PyImport_GetModuleDict

/* returns borrowed reference */
_DLL_EXPORT PyObject *getJavaModule(PyObject *module,
                                    const char *parent, const char *name) {
    PyObject *modules = PyImport_GetModuleDict();
    PyObject *parent_module, *full_name;

    if (parent[0] == '\0')
    {
        parent_module = NULL;
        full_name = PyString_FromString(name);
    }
    else if ((parent_module = PyDict_GetItemString(modules, parent)) == NULL)
    {
        PyErr_Format(PyExc_ValueError, "Parent module '%s' not found", parent);
        return NULL;
    }
    else
        full_name = PyString_FromFormat("%s.%s", parent, name);

    PyObject *child_module = PyDict_GetItem(modules, full_name);

    if (child_module == NULL)
    {
        child_module = PyModule_New(PyString_AS_STRING(full_name));
        if (child_module != NULL)
        {
            if (parent_module != NULL)
                PyDict_SetItemString(PyModule_GetDict(parent_module),
                                     name, child_module);
            PyDict_SetItem(modules, full_name, child_module);
            Py_DECREF(child_module);  /* borrow reference */
        }
    }
    Py_DECREF(full_name);

    /* During __install__ pass, __file__ is not yet set on module.
     * During __initialize__ pass, __file__ is passed down to child_module.
     */
    if (child_module != NULL)
    {
        PyObject *__file__ = PyString_FromString("__file__");
        PyObject *file = PyDict_GetItem(PyModule_GetDict(module), __file__);

        if (file != NULL)
            PyDict_SetItem(PyModule_GetDict(child_module), __file__, file);
        Py_DECREF(__file__);
    }

    return child_module;
}
开发者ID:ahua,项目名称:java,代码行数:50,代码来源:jcc.cpp


示例13: _PyStackless_Init

void
_PyStackless_Init(void)
{
	PyObject *dict;
	PyObject *modules;
	char *name = "stackless";
	PySlpModuleObject *m;

	if (init_slpmoduletype())
		return;

	/* record the thread state for thread support */
	slp_initial_tstate = PyThreadState_GET();

	/* smuggle an instance of our module type into modules */
	/* this is a clone of PyImport_AddModule */

	modules = PyImport_GetModuleDict();
	slp_module = slpmodule_new(name);
	if (slp_module == NULL || PyDict_SetItemString(modules, name, slp_module)) {
		Py_DECREF(slp_module);
		return;
	}
	Py_DECREF(slp_module); /* Yes, it still exists, in modules! */

	/* Create the module and add the functions */
	slp_module = Py_InitModule3("stackless", stackless_methods, stackless__doc__);
	if (slp_module == NULL)
		return; /* errors handled by caller */

	if (init_prickelpit()) return;

	dict = PyModule_GetDict(slp_module);

#define INSERT(name, object) \
	if (PyDict_SetItemString(dict, name, (PyObject*)object) < 0) return

	INSERT("slpmodule", PySlpModule_TypePtr);
	INSERT("cframe",    &PyCFrame_Type);
	INSERT("cstack",    &PyCStack_Type);
	INSERT("bomb",	    &PyBomb_Type);
	INSERT("tasklet",   &PyTasklet_Type);
	INSERT("channel",   &PyChannel_Type);
	INSERT("stackless", slp_module);

	m = (PySlpModuleObject *) slp_module;
	slpmodule_set__tasklet__(m, &PyTasklet_Type, NULL);
	slpmodule_set__channel__(m, &PyChannel_Type, NULL);
}
开发者ID:develersrl,项目名称:dspython,代码行数:49,代码来源:stacklessmodule.c


示例14: PyImport_GetModuleDict

void PyInviwo::importModule(const std::string& moduleName) {
    auto mainDict = PyImport_GetModuleDict();
    const static std::string __key__ = "__";
    char* key = new char[moduleName.size() + 5];
    sprintf(key, "__%s__", moduleName.c_str());
    if (PyDict_GetItemString(mainDict, key) == nullptr) {
        PyObject* pMod = PyImport_ImportModule(moduleName.c_str());
        if (nullptr != pMod) {
            PyDict_SetItemString(mainDict, key, pMod);
        } else {
            LogWarn("Failed to import python module: " << moduleName);
        }
    }
    delete[] key;
}
开发者ID:ResearchDaniel,项目名称:inviwo,代码行数:15,代码来源:pyinviwo.cpp


示例15: planner_python_env_new

static PlannerPythonEnv *
planner_python_env_new (const gchar *filename)
{
	PlannerPythonEnv *env;
	PyObject         *pDict, *pMain;

	env = g_new0 (PlannerPythonEnv,1);
	env->filename = g_strdup (filename);

	pDict = PyImport_GetModuleDict ();
	pMain = PyDict_GetItemString (pDict, "__main__");
	pDict = PyModule_GetDict (pMain);
	env->globals = PyDict_Copy (pDict);

	return env;
}
开发者ID:zsyyr,项目名称:Planner,代码行数:16,代码来源:planner-python-plugin.c


示例16: PyImport_ImportModuleEx

PyObject *
PyImport_ImportModuleEx(char *name)
{
    PyObject *modules;
    PyObject *m;

    PyImport_ImportFrozenModule(name);
    modules = PyImport_GetModuleDict();
    m = PyDict_GetItemString(modules, name);
    if (m == NULL) {
        printf("module %s not properly initialized\n", name);
        return NULL;
    }
    Py_INCREF(m);
    return m;
}
开发者ID:carriercomm,项目名称:cleese,代码行数:16,代码来源:import.c


示例17: reload_module

PyObject *
reload_module(PyObject *m)
{
	PyObject *modules = PyImport_GetModuleDict();
	PyObject *path = NULL;
	char *name, *subname;

	if (m == NULL || !PyModule_Check(m)) {
		PyErr_SetString(PyExc_TypeError,
				"reload_module() argument must be module");
		return NULL;
	}
	name = PyModule_GetName(m);
	if (name == NULL)
		return NULL;
	if (m != PyDict_GetItemString(modules, name)) {
		PyErr_Format(PyExc_ImportError,
			     "reload(): module %.200s not in sys.modules",
			     name);
		return NULL;
	}
	subname = strrchr(name, '.');
	if (subname == NULL)
		subname = name;
	else {
		PyObject *parentname, *parent;
		parentname = PyString_FromStringAndSize(name, (subname-name));
		if (parentname == NULL)
			return NULL;
		parent = PyDict_GetItem(modules, parentname);
		Py_DECREF(parentname);
		if (parent == NULL) {
			PyErr_Format(PyExc_ImportError,
			    "reload(): parent %.200s not in sys.modules",
			    name);
			return NULL;
		}
		subname++;
		path = PyObject_GetAttrString(parent, "__path__");
		if (path == NULL)
			PyErr_Clear();
	}
	m = call_find_load(name, subname, path);
	Py_XDECREF(path);
	return m;
}
开发者ID:pganti,项目名称:micheles,代码行数:46,代码来源:cimport.c


示例18: checkStartupSuccess

static bool checkStartupSuccess() {
	PyObject* mods = PyImport_GetModuleDict();
	if(!mods) return false;
	PyObject* m = PyDict_GetItemString(mods, "main");
	if(!m) return false;

	PyObject* successObj = PyObject_GetAttrString(m, "successStartup");
	bool success = false;
	if(successObj)
		success = PyObject_IsTrue(successObj);
	
	Py_XDECREF(successObj);
	mods = NULL; // borrowed
	m = NULL; // borrowed
	
	return success;
}
开发者ID:BMXE,项目名称:music-player,代码行数:17,代码来源:main.cpp


示例19: InitPyVcl

/** Initialize the vcl module. This creates all types need by PyVcl and the vcl object,
 *  which is placed in the list of imported modules.
 *  This way you can write "import vcl" instead of "from PyVcl import vcl". 
 */
PyObject* InitPyVcl()
{
	PyObject *PyVclModule = PyModule_Create(&PyVclModuleDef);
	if(PyType_Ready(&GlobalVclType) < 0 || PyType_Ready(&VclMethodType) < 0 ||
		PyType_Ready(&VclObjectType) < 0 || PyType_Ready(&VclFunctionType) < 0 ||
		PyType_Ready(&VclArrayPropertyType) < 0 || PyType_Ready(&VclRefType) < 0)
		return NULL;
	PyVclException = PyErr_NewException("vcl.VclError", NULL, NULL);
	PyModule_AddObject(PyVclModule, "VclError", PyVclException);

	PyObject *vcl = GlobalVcl_Create();
	PyModule_AddObject(PyVclModule, "vcl", vcl);

	PyObject *Modules = PyImport_GetModuleDict();
	PyDict_SetItemString(Modules, "vcl", vcl);
	Py_DECREF(vcl);
	return PyVclModule;
}
开发者ID:q2apro,项目名称:graph-padowan,代码行数:22,代码来源:PyVcl.cpp


示例20: PyThreadState_GET

PyObject *GPU_initPython(void)
{
	PyObject *module;
	PyObject *submodule;
	PyObject *sys_modules = PyThreadState_GET()->interp->modules;

	module = PyInit_gpu();

	PyModule_AddObject(module, "export_shader", (PyObject *)PyCFunction_New(meth_export_shader, NULL));

	/* gpu.offscreen */
	PyModule_AddObject(module, "offscreen", (submodule = BPyInit_gpu_offscreen()));
	PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
	Py_INCREF(submodule);

	PyDict_SetItem(PyImport_GetModuleDict(), PyModule_GetNameObject(module), module);
	return module;
}
开发者ID:UPBGE,项目名称:blender,代码行数:18,代码来源:gpu.c



注:本文中的PyImport_GetModuleDict函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PyIndex_Check函数代码示例发布时间:2022-05-30
下一篇:
C++ PyImport_AddModule函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap