I am writing Python extension modules for my C++ application. Also, I embedded Python interpreter in the same application and use these modules. So, I am not building separately these extension modules, because modules are created and used in the same application (just add PyImport_AppendInittab("modulename", &PyInit_modulename) before the Py_Initialize()).
If I do it like this is it possible to create Python package structure?
Currently, I have import module, but I need to have the possibility to use import package.module in my embedded Python interpreter.
Is there anything for creating packages like there is a function for modules PyModule_Create()?
-
You can try to build module dynamically like in this answer: stackoverflow.com/questions/3799545/…Stanislav Ivanov– Stanislav Ivanov2016年10月27日 14:01:37 +00:00Commented Oct 27, 2016 at 14:01
-
No, it does not help me.kjrkvc– kjrkvc2016年10月28日 06:38:38 +00:00Commented Oct 28, 2016 at 6:38
1 Answer 1
My further research shows that it is not possible to have packages structure in extension modules. Actually, you can create the structure using a simple trick, add a module to existing module as an object. For example, you can create the structure like this: mod1.mod2.mod3. But, it's not same like packages. You cannot use import mod1.mod2 or import mod1.mod2.mod3. You have to use import mod1, and that will import all modules. No way to import just one module.