You Are Here:

Community: Developer Discussion Boards

#1 Old Embedding Pyhton in C++ - 2009-04-21, 13:50

Join Date: Mar 2004
Posts: 1,926
Location: Czech Republic
stenlik's Avatar
stenlik
Online
Forum Nokia Champion
Hi,

is there any way how to execute the Python module function from char* bufer? Now I'm using the PyImport_Import to load the '.py' module but I would prefer to provide the char* buffer to the interpreter instead. I have found only the PyRun_SimpleString but it does not give me the flexibility of providing the input parameters and checking the result...

Thanks a lot,
BR
STeN
Reply With Quote

#2 Old Re: Embedding Pyhton in C++ - 2009-04-21, 23:05

Join Date: Mar 2003
Posts: 125
Location: UK
aya42
Offline
Regular Contributor
Quote:
Originally Posted by stenlik View Post
is there any way how to execute the Python module function from char* bufer? Now I'm using the PyImport_Import to load the '.py' module but I would prefer to provide the char* buffer to the interpreter instead. I have found only the PyRun_SimpleString but it does not give me the flexibility of providing the input parameters and checking the result...
Do you mean you want to import a module, then call a function from that module? If so, you want something like...

Code:
Py_Initialize();

PyObject* module = PyImport_ImportModule("mymodule");
PyObject* func = PyObject_GetAttrString(module, "myfunction");
PyObject* result = PyObject_CallObject(func, NULL);

// Do something with 'result'

Py_DECREF(result);
Py_DECREF(func);
Py_DECREF(module);

Py_Finalize();
There's a more complete example at http://docs.python.org/extending/emb...pure-embedding.

If you meant something else, then please clarify.
Reply With Quote

#3 Old Re: Embedding Pyhton in C++ - 2009-04-23, 18:26

Join Date: Mar 2004
Posts: 1,926
Location: Czech Republic
stenlik's Avatar
stenlik
Online
Forum Nokia Champion
Hi,

thanks for reply! |But I do not want to import module from file - this is already working for me. The problem is that when I use the PyImport_Import I need to have saved the Python script in the .py file. What I need is to construct the script body dynamically in C++ and provide it to the interpreter as a char* buffer... (of course I can save it to some tepmorary file, but this is not too nice solution). The only method I have found was PyRun_SimpleString - but it does not allow to handle complex scenarios with passing paramateres, readign result, etc.

BR
STeN
Reply With Quote

#4 Old Re: Embedding Pyhton in C++ - 2009-04-23, 21:49

Join Date: Mar 2003
Posts: 125
Location: UK
aya42
Offline
Regular Contributor
Quote:
Originally Posted by stenlik View Post
The only method I have found was PyRun_SimpleString - but it does not allow to handle complex scenarios with passing paramateres, readign result, etc.
I'm not sure I understand. If you want to generate a fixed char* buffer with the code, and then execute it, I don't see where the 'passing parameters' applies.

Unless you mean you want the Python module to call back into C functions, in which case you need to use a combination of embedding and extending.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
embedding Open C in a SIS file pzul_wisner Open C/C++ 4 2008-01-23 20:56
Application embedding in 3rd edition symbianyucca General Symbian C++ 13 2007-04-27 05:55
Application Embedding skumar_rao General Symbian C++ 0 2007-04-27 05:51
Client/server-framework, embedding, 3rd ed. tsippa Symbian User Interface 4 2007-01-26 12:07
Application embedding using Ecom plugin (S60 3rd MR) akrapacs Symbian User Interface 0 2006-09-20 17:14

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d81449X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZpythonQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZuserE5ftagQSxpythonX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ