×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    39

    embedding python in Symbian C++ and passing arguments

    Hello all,
    I m new in Python but i'm interested by the scripting capabilities that it offers.
    My idea is to use python module to execute certain actions, meaning that instead of recompiling the whole Symbian application i ll just upload a new python script.
    Any body used use python this way?

    Then i have a problem passing argument to a Python function.
    I use :

    PyObject *arglist = Py_BuildValue("sss", arg1ptr, arg2ptr, arg3ptr);

    i m hoping to pass arglist to python.

    My python function would be like :

    def foo(arg1, arg2, arg3):

    Unfortunatly it doesn't work... Actually the module is not even found. It works if i don't use parameters...

    I'm quite confuse. Can anybody help me?

    Thanks for your help

    Julien

  2. #2
    Registered User
    Join Date
    Feb 2005
    Location
    Belgium (Europe)
    Posts
    1,352

    Re: embedding python in Symbian C++ and passing arguments

    Quote Originally Posted by papana View Post
    Hello all,
    I m new in Python but i'm interested by the scripting capabilities that it offers.
    My idea is to use python module to execute certain actions, meaning that instead of recompiling the whole Symbian application i ll just upload a new python script.
    Any body used use python this way?

    Then i have a problem passing argument to a Python function.
    I use :

    PyObject *arglist = Py_BuildValue("sss", arg1ptr, arg2ptr, arg3ptr);

    i m hoping to pass arglist to python.

    My python function would be like :

    def foo(arg1, arg2, arg3):

    Unfortunatly it doesn't work... Actually the module is not even found. It works if i don't use parameters...

    I'm quite confuse. Can anybody help me?

    Thanks for your help

    Julien
    Hello Julien

    I think that this wiki page will be useful for you : how to call bar.foo(arg1) !

    happy symbian programming

    Cyke64
    pys60 1.4.5 and 2.0.0, pygame, PyS60 CE on E90 and 5800 !

    Find my pys60 extension modules on cyke64.googlepages.com

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    39

    Re: embedding python in Symbian C++ and passing arguments

    Thanks for your reply, I had this example in mind but i still don't get it to pass more than one param.

    Here is my c++ source

    Code:
    char *module_name = "rivos1" ;
    char *foo = "foo" ;
    char *response = "" ;
    
    TInt32 r_len = 0 ;
    PyObject *pModule = PyImport_ImportModule(module_name) ;
    
    if ( pModule != NULL )
    {
    	
        TBuf8<TEXT_SIZE_SMALL> arg1;
        TBuf8<TEXT_SIZE_SMALL> arg2;
        TBuf8<TEXT_SIZE_SMALL> arg3;
        
        arg1.Append(_L8("arg1text"));
        arg2.Append(_L8("arg2text"));
        arg3.Append(_L8("arg3text"));
        char* arg1ptr = (char*)arg1.PtrZ(); 
        char* arg2ptr = (char*)arg2.PtrZ(); 
        char* arg3ptr = (char*)arg3.PtrZ(); 
    	
        PyObject *module_dict = PyModule_GetDict(pModule);
        PyObject *expression = PyDict_GetItemString(module_dict, foo);
        PyObject *arglist = Py_BuildValue("(sss)", arg1ptr, arg2ptr, arg3ptr);
    
        PyObject *result = PyEval_CallObject(expression, arglist);
    	  	
        if (result)
        	response = PyString_AsString( result ) ;
    	    	
        if (response)
        	r_len = strlen( response ) ;
    }
    		
    // Clean-up, and restore thread state
    PyEval_SaveThread();
    CleanupStack::PopAndDestroy(it);
    And here is the python script (located in c:\resource\rivos1.py):

    Code:
    import e32
    import os
    
    def foo(arg1, arg2, arg3):
    	# drefine the directory and file name to write the file into
    	imagedir=u'c:\\witetest.txt'
    
    	# create the file
    	file = open(imagedir,'w')
    
    	# write some text into it
    	file.write(arg1+' '+arg2+' '+arg3)
    
    	# close the file
    	file.close()
    
    foo(arg1, arg2, arg3)
    but it doesn't work
    I can't find any doc... I need your help
    THanks!

    Julien

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    39

    Re: embedding python in Symbian C++ and passing arguments

    Hello all,
    Ok I solved it!
    My mistake was to think that i had to give an entry point to the Python script.

    I was doing (after the declaration of the function) :
    foo(arg1, arg2, arg3)

    And this was the error, it is not needed at all!

    Julien

Similar Threads

  1. Replies: 11
    Last Post: 2009-05-04, 07:24
  2. Replies: 2
    Last Post: 2007-04-25, 09:52
  3. symbian client/server message passing problem .
    By siemensc55 in forum Symbian
    Replies: 1
    Last Post: 2005-09-12, 04:29
  4. Passing runtime parameters to CLDC HI under Symbian 8.0
    By tal.elad in forum Mobile Java General
    Replies: 0
    Last Post: 2005-04-13, 11:10
  5. Passing arguments
    By franalegre in forum Symbian User Interface
    Replies: 0
    Last Post: 2003-04-23, 11:30

Posting Permissions

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