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()
?
Asked
Active
Viewed 192 times
0

kjrkvc
- 115
- 2
- 12
-
You can try to build module dynamically like in this answer: http://stackoverflow.com/questions/3799545/dynamically-importing-python-module – Stanislav Ivanov Oct 27 '16 at 14:01
-
No, it does not help me. – kjrkvc Oct 28 '16 at 06:38
1 Answers
0
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.

kjrkvc
- 115
- 2
- 12