Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #71678 > unrolled thread

Re: Loading modules from files through C++

Started byStefan Behnel <stefan_ml@behnel.de>
First post2014-05-17 13:58 +0200
Last post2014-05-17 13:58 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Loading modules from files through C++ Stefan Behnel <stefan_ml@behnel.de> - 2014-05-17 13:58 +0200

#71678 — Re: Loading modules from files through C++

FromStefan Behnel <stefan_ml@behnel.de>
Date2014-05-17 13:58 +0200
SubjectRe: Loading modules from files through C++
Message-ID<mailman.10081.1400327955.18130.python-list@python.org>
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 totally stuck at the
> finally loading step.
> 
> I've got this a C++ loader method "load_module(fullname)" which does
> load the requested module script files into a null-terminated string. I
> know that "load_module" has to return the module PyObject*. But I can't
> get the python source in the c-string into a module PyObject*.
> [...]
> Can anybody help how in gods name one is supposed to create a module
> from an in-memory c-string when called from within load_module (or
> anywhere)?

Looks like you want to implement a SourceLoader:

https://docs.python.org/3.4/library/importlib.html#importlib.abc.SourceLoader

I recommend implementing this in Python code instead of C code, though.
Much easier. Cython can help with the integration between both.

Stefan

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web