0

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 Oct 27, 2016 at 12:34
2
  • You can try to build module dynamically like in this answer: stackoverflow.com/questions/3799545/… Commented Oct 27, 2016 at 14:01
  • No, it does not help me. Commented Oct 28, 2016 at 6:38

1 Answer 1

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.

answered Dec 5, 2016 at 9:53
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.