Re: Loading modules from files through C++

2014-07-08 Thread Roland Plüss
On Wed, May 21, 2014 at 3:17 AM, Roland Plüss rol...@rptd.ch wrote: The important part are the last two lines. An important module is lacking the __builtins__ dictionary member so I had to add it. Hopefully this works also in Py3 should I switch some time later. But I guess it should seeing

Re: Loading modules from files through C++

2014-06-03 Thread Roland Plüss
I came now a bit further with Python 3 but I'm hitting a total road-block right now with the importer in C++ which worked in Py2 but is now totally broken in Py3. In general I've got a C++ class based module which has two methods: { find_module, ( PyCFunction )spModuleModuleLoader::cfFindModule,

Re: Loading modules from files through C++

2014-05-24 Thread Roland Plüss
# CODE # PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL }; moduledef.m_name = MyModule; moduledef.m_doc = MyModule; pModule = PyModule_Create( moduledef ); PyState_AddModule( pModule, moduledef ); PyRun_SimpleString( print( globals() )\n );

Re: Loading modules from files through C++

2014-05-21 Thread Stefan Behnel
Roland Plüss, 20.05.2014 19:17: PyObject * const loadedModule = Py_InitModule3( fullname, NULL, Loaded module ); PyObject * const moduleDict = PyModule_GetDict( loadedModule ); // borrowed reference PyDict_SetItemString( moduleDict, __builtins__, PyEval_GetBuiltins() ); PyRun_StringFlags(

Re: Loading modules from files through C++

2014-05-21 Thread Roland Plüss
On 05/20/2014 07:55 PM, Chris Angelico wrote: On Wed, May 21, 2014 at 3:17 AM, Roland Plüss rol...@rptd.ch wrote: The important part are the last two lines. An important module is lacking the __builtins__ dictionary member so I had to add it. Hopefully this works also in Py3 should I switch

Re: Loading modules from files through C++

2014-05-20 Thread Roland Plüss
On 05/19/2014 03:40 AM, Chris Angelico wrote: On Mon, May 19, 2014 at 5:41 AM, Roland Plüss rol...@rptd.ch wrote: This exec source_code in module.__dict__ , should this not also be doable with PyEval_EvalCode? General principle: The more code you write in Python and the less in C/C++, the

Re: Loading modules from files through C++

2014-05-20 Thread Chris Angelico
On Wed, May 21, 2014 at 3:17 AM, Roland Plüss rol...@rptd.ch wrote: The important part are the last two lines. An important module is lacking the __builtins__ dictionary member so I had to add it. Hopefully this works also in Py3 should I switch some time later. But I guess it should seeing

Re: Loading modules from files through C++

2014-05-19 Thread Roland Plüss
On 05/19/2014 03:40 AM, Chris Angelico wrote: On Mon, May 19, 2014 at 5:41 AM, Roland Plüss rol...@rptd.ch wrote: This exec source_code in module.__dict__ , should this not also be doable with PyEval_EvalCode? General principle: The more code you write in Python and the less in C/C++, the

Re: Loading modules from files through C++

2014-05-19 Thread Michael Torrie
On 05/17/2014 08:01 AM, Stefan Behnel wrote: please avoid top-posting. Trimming quoted material where appropriate is always welcome too! -- https://mail.python.org/mailman/listinfo/python-list

Re: Loading modules from files through C++

2014-05-18 Thread Roland Plüss
On 05/17/2014 07:05 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 18:28: On 05/17/2014 05:49 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 17:28: On 05/17/2014 04:01 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 15:49: On 05/17/2014 03:26 PM, Stefan Behnel wrote: Roland Plüss,

Re: Loading modules from files through C++

2014-05-18 Thread Chris Angelico
On Mon, May 19, 2014 at 5:41 AM, Roland Plüss rol...@rptd.ch wrote: This exec source_code in module.__dict__ , should this not also be doable with PyEval_EvalCode? General principle: The more code you write in Python and the less in C/C++, the happier and more productive you will be. Drop into

Re: Loading modules from files through C++

2014-05-17 Thread Stefan Behnel
Roland Plüss, 17.05.2014 02:27: I'm using Python in an embedded situation. In particular I have to load python scripts through a memory interface so regular python module loading can not be used. I got working so far a module loader object I've added using C++ to sys.meta_path . Now I'm

Re: Loading modules from files through C++

2014-05-17 Thread Roland Plüss
That doesn't work in 2.x, doesn't it? On 05/17/2014 01:58 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 02:27: I'm using Python in an embedded situation. In particular I have to load python scripts through a memory interface so regular python module loading can not be used. I got working

Re: Loading modules from files through C++

2014-05-17 Thread Stefan Behnel
Roland Plüss, 17.05.2014 15:00: On 05/17/2014 01:58 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 02:27: I'm using Python in an embedded situation. In particular I have to load python scripts through a memory interface so regular python module loading can not be used. I got working so far

Re: Loading modules from files through C++

2014-05-17 Thread Roland Plüss
I'm willing to go to Py3 but only if the solution to the problem is simpler than getting it fixed in Py2. So some questions first: - does this importlib stuff you showed there apply to C++ land (I need to fully drive it from C++ not Python code)? - is the C++ land of Py3 similar to Py2 or totally

Re: Loading modules from files through C++

2014-05-17 Thread Stefan Behnel
Hi, please avoid top-posting. Roland Plüss, 17.05.2014 15:49: On 05/17/2014 03:26 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 15:00: On 05/17/2014 01:58 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 02:27: I'm using Python in an embedded situation. In particular I have to load

Re: Loading modules from files through C++

2014-05-17 Thread Roland Plüss
On 05/17/2014 04:01 PM, Stefan Behnel wrote: Hi, please avoid top-posting. Roland Plüss, 17.05.2014 15:49: On 05/17/2014 03:26 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 15:00: On 05/17/2014 01:58 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 02:27: I'm using Python in an

Re: Loading modules from files through C++

2014-05-17 Thread Stefan Behnel
Roland Plüss, 17.05.2014 17:28: On 05/17/2014 04:01 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 15:49: On 05/17/2014 03:26 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 15:00: On 05/17/2014 01:58 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 02:27: I'm using Python in an

Re: Loading modules from files through C++

2014-05-17 Thread Roland Plüss
On 05/17/2014 05:49 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 17:28: On 05/17/2014 04:01 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 15:49: On 05/17/2014 03:26 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 15:00: On 05/17/2014 01:58 PM, Stefan Behnel wrote: Roland Plüss,

Re: Loading modules from files through C++

2014-05-17 Thread Stefan Behnel
Roland Plüss, 17.05.2014 18:28: On 05/17/2014 05:49 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 17:28: On 05/17/2014 04:01 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 15:49: On 05/17/2014 03:26 PM, Stefan Behnel wrote: Roland Plüss, 17.05.2014 15:00: On 05/17/2014 01:58 PM,