You Are Here:

Community: Developer Discussion Boards

#1 Old Running Python-scripts from Symbian C++ code - 2005-01-25, 16:35

Join Date: Jan 2005
Posts: 2
markol
Offline
Registered User
I have trouble running a Python script from Symbian C++ code. Could someone give me an example of this?

I have tried:

-using CSPyInterpreter, but the code does not compile/link correctly. I have added some headers to Symbian SDK's include from "C:\Symbian\7.0s\Series60_v20\python-port-s60\symbian_python\Include", but it doesn't seem to work. This lead to missing io.h, which doesn't seem to exist. I'm using MS VC++.

-using RApaLsSession::StartApp(const CApaCommandLine& aCommandLine), but I don't know what to use in CApaCommandLine::SetDocumentNameL(const TDesC& aDocName). This almost opens the Pyhton script; the title can be seen, but the application does not run. Maybe something to do with ViewUID's, but I haven't found that concept from the documentation.

If someone has done this, I'll appreciate the help.

--Marko
Reply With Quote

#2 Old Re: Running Python-scripts from Symbian C++ code - 2005-01-26, 09:18

Join Date: Sep 2003
Posts: 209
Location: Finland
otsov
Offline
Regular Contributor
Quote:
Originally posted by markol


-using CSPyInterpreter, but the code does not compile/link correctly. I have added some headers to Symbian SDK's include from "C:\Symbian\7.0s\Series60_v20\python-port-s60\symbian_python\Include", but it doesn't seem to work. This lead to missing io.h, which doesn't seem to exist. I'm using MS VC++.

This answer only considers the "CSPyInterpreter"-option:

1) In ".mmp"-file you have to have line:

LIBRARY python222.lib

2) Include:

#include "CSPyInterpreter.h"

3) Running a script (you might want to consider wrapping this e.g. with "CAsyncCallBack"):

CSPyInterpreter* iInterpreter;

iInterpreter = CSPyInterpreter::NewInterpreterL();

TBuf8<KMaxFileName> outputBuffer;

... outputBuffer is filled with a proper script name, e.g. "default.py" ...

char *argv[1];
int argc;
argv[0] = (char*)outputBuffer.PtrZ();
argc = 1;

iInterpreter->RunScript(argc, argv);

delete iInterpreter;
iInterpreter = NULL;

4) If your target is ".exe" you might have to increase the stacksize, for example in ".mmp"-file:

EPOCSTACKSIZE 65536
Reply With Quote

#3 Old 2005-01-26, 13:37

Join Date: Jan 2005
Posts: 2
markol
Offline
Registered User
Thanks, I think this will do the trick.

It seems, that the CSPyInterpreter is not included in every version of Python for Series60 SDK. My problem is, that I have to use the Symbian 7.0 SDK (and therefore the Python SDK for that). The CSPyInterpreter seems to be included in the Python SDK for Symbian 8.0 (which is Python_1_0_for_Series60_SDK_2nd_ed_FP2).

My next question is, has anyone lauched Python code using Symbian 7.0 SDK? Adding just the CSPyInterpreter.h to the older environment does not work.

--Marko
Reply With Quote

#4 Old Re: Running Python-scripts from Symbian C++ code - 2005-09-07, 11:10

Join Date: Aug 2004
Posts: 290
simo.salminen
Offline
Regular Contributor
Here is how you can use other Python C API. This works with latest 1.1.6 alpha.

<code>
CSPyInterpreter* it = CSPyInterpreter::NewInterpreterL();
CleanupStack::PushL(it);
PyEval_RestoreThread(PYTHON_TLS->thread_state);

PyRun_SimpleString("open(r'c:\\foo.txt', 'w').write('hello')\n");

PyEval_SaveThread();
CleanupStack::PopAndDestroy(it);
</code>

One thing that does not seem to work is calls to appuifw module.
Reply With Quote

#5 Old Re: Running Python-scripts from Symbian C++ code - 2005-09-13, 13:07

Join Date: Aug 2004
Posts: 290
simo.salminen
Offline
Regular Contributor
Here is how you can print out error messages from Python C API:

First, define following function:
int PythonOutput(const char *buf, int n)
{
HBufC* buf16 = HBufC::NewLC(n);
buf16->Des().Copy(TPtrC8((unsigned char*)buf, n));
RDebug::Print(_L("[PYTHON ERROR]: %S"), buf16);
CleanupStack::PopAndDestroy();
return n;
}


Then, after interpreter is started, do following:
CSPyInterpreter* it = CSPyInterpreter::NewInterpreterL();
CleanupStack::PushL(it);
it->iStdO = &PythonOutput;


Now you can use if (PyErr_Occurred()) { PyErr_Print(); } to find out about errors.
Last edited by simo.salminen : 2006-08-23 at 16:26.
Reply With Quote

#6 Old Re: Running Python-scripts from Symbian C++ code - 2007-11-14, 22:06

Join Date: Nov 2007
Posts: 6
nithin
Offline
Registered User
hii,
I'm new to symbian environment....
I've a small problem here...

I'm writing an application which calls for some python functions...

My Symbian-Python directory is in C:\Symbian\8.0a\S60_2nd_FP2\python-port-s60

While my app is in
C:\Symbian\8.0a\S60_2nd_FP2\Series60Ex

So whn i include Symbian-Python as user include in da mmp file of my application, its taking da address as
..\MyApp\group\C:\Symbian\8.0a\S60_2nd_FP2\Series60Ex

I need some help in this regard...its really urgent...so plz reply if some1 can help me in dis regard....
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

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