I'm trying to extend Python interpreter by a few C functions I wrote. From reading docs, to expose those function the user has to import the module encompassing the functions.
Is it possible to load pre-load or pre-import via C API the module so that the user doesn't have to type import <mymodule>? Or even better, from <mymodule> import <function>?
Edit: I can do PyRun_SimpleString("from mymodule import myfunction") just after Py_Initialize(); - I was just wondering if there is another way of doing this..?
Edit 2: In other words, I have an application written in C which embeds a Python interpreter. That application provides some functionality which I want to expose to the users so they can write simple Python scripts for the app. All I want is to remove the need of writing from mymodule import myfunction1, myfunction2 because, since it is very specialized app and the script wont work without the app anyway, it doesn't make sense to require to import ... all the time.
Nope. You could add it to the Python interpreter itself, but that would mean creating a custom Python version, which, I guess, is not what you want.
That import <mymodule> is not just for loading the module, it's also for making this module visible in the (main|current) namespace. Being able to do that, w/o hacking the actual Python interpreter, would run against "Explicit is better than implicit" very strongly.
Extending Python: pre-load my C module