Re: [BangPypers] Calling Python script from C++.
if this thread is still active - instead of passing the argument , probably the argument can be extracted from a temporary file/buffer. a small code can be inserted to the python code sent as argument to PyRun_SimpleString() to read it. steve-391 wrote: > > Hi, > > On 02/25/2010 07:32 PM, lakshmi.chow...@bt.com wrote: >> Hi Zubin, >> >> [...snip...] >> In the function definition, I am taking 1 hard coded variable and needs >> to pass this variable along with the string(python code) to >> PyRun_SimpleString() and execute it. >> >> Could you tell me the solution how to map the argument to the >> string(python code) and pass to PyRun_SimpleString() and execute >> successfully? >> > > Is there any specific reason you choose to read the entire file and > execute it > using PyRun_SimpleString() as opposed to the more traditional and standard > methods of using fork()+exec*() or system() functions ? > > cheers, > - steve > > -- > random non tech spiel: http://lonetwin.blogspot.com/ > tech randomness: http://lonehacks.blogspot.com/ > what i'm stumbling into: http://lonetwin.stumbleupon.com/ > ___ > BangPypers mailing list > BangPypers@python.org > http://mail.python.org/mailman/listinfo/bangpypers > > -- View this message in context: http://old.nabble.com/Re%3A-Calling-Python-script-from-C%2B%2B.-tp27715952p27768904.html Sent from the BangPypers - Bangalore Python Users Group mailing list archive at Nabble.com. ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Calling Python script from C++.
Hi, On 02/25/2010 07:32 PM, lakshmi.chow...@bt.com wrote: Hi Zubin, [...snip...] In the function definition, I am taking 1 hard coded variable and needs to pass this variable along with the string(python code) to PyRun_SimpleString() and execute it. Could you tell me the solution how to map the argument to the string(python code) and pass to PyRun_SimpleString() and execute successfully? Is there any specific reason you choose to read the entire file and execute it using PyRun_SimpleString() as opposed to the more traditional and standard methods of using fork()+exec*() or system() functions ? cheers, - steve -- random non tech spiel: http://lonetwin.blogspot.com/ tech randomness: http://lonehacks.blogspot.com/ what i'm stumbling into: http://lonetwin.stumbleupon.com/ ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Calling Python script from C++.
Hi Zubin, Thanks a lot for the quick reply. You are correct Zubin, we can execute python script individually as you described. But my requirement is that, Basically I want to call the python script from c++ program. In the c++ program, I am creating the multi threads and calling the thread function with a argument(argument contains the entire python code as a string, for example > Def sayHello(name): > Print "Hello" + name > > sayHello(arg)). In the function definition, I am taking 1 hard coded variable and needs to pass this variable along with the string(python code) to PyRun_SimpleString() and execute it. Could you tell me the solution how to map the argument to the string(python code) and pass to PyRun_SimpleString() and execute successfully? Thanks, Lakshmi. -Original Message- From: bangpypers-bounces+lakshmi.chowdam=bt@python.org [mailto:bangpypers-bounces+lakshmi.chowdam=bt@python.org] On Behalf Of Zubin Mithra Sent: Thursday, February 25, 2010 6:59 PM To: Bangalore Python Users Group - India Subject: Re: [BangPypers] Calling Python script from C++. #!/usr/bin/python # test.py import sys print sys.argv $ python test.py myArgument i hope this is what you required. On 2/25/10, lakshmi.chow...@bt.com wrote: > Hi Zubin, > > Deployment OS is RedHat Linux. > > Here is the python file : Hello.py > > Def sayHello(name): > Print "Hello" + name > > sayHello(arg) > > and > > In c++ file, I am catching all the lines from the python file in string > buffer and calling the PyRun_SimpleString(stringbuffer). > It is working fine without passing any argument. But I want to send the > argument to this python file from c++ file. > > Could you tell me how can I pass arguments to python file? > > > Thanks, > Lakshmi. > > -Original Message- > From: bangpypers-bounces+lakshmi.chowdam=bt@python.org > [mailto:bangpypers-bounces+lakshmi.chowdam=bt@python.org] On Behalf Of > Zubin Mithra > Sent: Thursday, February 25, 2010 5:11 PM > To: Bangalore Python Users Group - India > Subject: Re: [BangPypers] Calling Python script from C++. > > could you give us a few more details? the deployment OS? > > > cheers!!! > Zubin > > > > On Thu, Feb 25, 2010 at 12:51 PM, wrote: >> Hi, >> >> >> >> We have a requirement of Calling Python script from C++. >> >> >> >> So, For this we are trying to pass entire python script(Script has both >> method implementation and method calls are exist) as a string and >> executing this string by using PyRun_SimpleString(). >> >> >> >> Our concern is that if python has a method with no arguments we are able >> to execute it successfully >> >> >> >> But If Method takes parameters or arguments ,then how do we can pass >> values to that method and how can we execute it? >> >> >> >> Could you please provide the solution. >> >> >> >> Thanks and Regards, >> >> Lakshmi Narasaiah C, >> >> >> >> ___ >> BangPypers mailing list >> BangPypers@python.org >> http://mail.python.org/mailman/listinfo/bangpypers >> > ___ > BangPypers mailing list > BangPypers@python.org > http://mail.python.org/mailman/listinfo/bangpypers > ___ > BangPypers mailing list > BangPypers@python.org > http://mail.python.org/mailman/listinfo/bangpypers > -- cheers!!! Zubin ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Calling Python script from C++.
Can you show me the stringbuffer what it contains? On Thu, Feb 25, 2010 at 6:58 PM, Zubin Mithra wrote: > #!/usr/bin/python > # test.py > import sys > print sys.argv > > > $ python test.py myArgument > > i hope this is what you required. > > > > On 2/25/10, lakshmi.chow...@bt.com wrote: > > Hi Zubin, > > > > Deployment OS is RedHat Linux. > > > > Here is the python file : Hello.py > > > > Def sayHello(name): > > Print "Hello" + name > > > > sayHello(arg) > > > > and > > > > In c++ file, I am catching all the lines from the python file in string > > buffer and calling the PyRun_SimpleString(stringbuffer). > > It is working fine without passing any argument. But I want to send the > > argument to this python file from c++ file. > > > > Could you tell me how can I pass arguments to python file? > > > > > > Thanks, > > Lakshmi. > > > > -Original Message- > > From: bangpypers-bounces+lakshmi.chowdam=bt@python.org > > [mailto:bangpypers-bounces+lakshmi.chowdam > =bt@python.org] On Behalf Of > > Zubin Mithra > > Sent: Thursday, February 25, 2010 5:11 PM > > To: Bangalore Python Users Group - India > > Subject: Re: [BangPypers] Calling Python script from C++. > > > > could you give us a few more details? the deployment OS? > > > > > > cheers!!! > > Zubin > > > > > > > > On Thu, Feb 25, 2010 at 12:51 PM, wrote: > >> Hi, > >> > >> > >> > >> We have a requirement of Calling Python script from C++. > >> > >> > >> > >> So, For this we are trying to pass entire python script(Script has both > >> method implementation and method calls are exist) as a string and > >> executing this string by using PyRun_SimpleString(). > >> > >> > >> > >> Our concern is that if python has a method with no arguments we are able > >> to execute it successfully > >> > >> > >> > >> But If Method takes parameters or arguments ,then how do we can pass > >> values to that method and how can we execute it? > >> > >> > >> > >> Could you please provide the solution. > >> > >> > >> > >> Thanks and Regards, > >> > >> Lakshmi Narasaiah C, > >> > >> > >> > >> ___ > >> BangPypers mailing list > >> BangPypers@python.org > >> http://mail.python.org/mailman/listinfo/bangpypers > >> > > ___ > > BangPypers mailing list > > BangPypers@python.org > > http://mail.python.org/mailman/listinfo/bangpypers > > ___ > > BangPypers mailing list > > BangPypers@python.org > > http://mail.python.org/mailman/listinfo/bangpypers > > > > > -- > cheers!!! > Zubin > ___ > BangPypers mailing list > BangPypers@python.org > http://mail.python.org/mailman/listinfo/bangpypers > -- Praveen Kumar +91 9620621342 http://praveensunsetpoint.wordpress.com Bangalore ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Calling Python script from C++.
#!/usr/bin/python # test.py import sys print sys.argv $ python test.py myArgument i hope this is what you required. On 2/25/10, lakshmi.chow...@bt.com wrote: > Hi Zubin, > > Deployment OS is RedHat Linux. > > Here is the python file : Hello.py > > Def sayHello(name): > Print "Hello" + name > > sayHello(arg) > > and > > In c++ file, I am catching all the lines from the python file in string > buffer and calling the PyRun_SimpleString(stringbuffer). > It is working fine without passing any argument. But I want to send the > argument to this python file from c++ file. > > Could you tell me how can I pass arguments to python file? > > > Thanks, > Lakshmi. > > -Original Message- > From: bangpypers-bounces+lakshmi.chowdam=bt@python.org > [mailto:bangpypers-bounces+lakshmi.chowdam=bt@python.org] On Behalf Of > Zubin Mithra > Sent: Thursday, February 25, 2010 5:11 PM > To: Bangalore Python Users Group - India > Subject: Re: [BangPypers] Calling Python script from C++. > > could you give us a few more details? the deployment OS? > > > cheers!!! > Zubin > > > > On Thu, Feb 25, 2010 at 12:51 PM, wrote: >> Hi, >> >> >> >> We have a requirement of Calling Python script from C++. >> >> >> >> So, For this we are trying to pass entire python script(Script has both >> method implementation and method calls are exist) as a string and >> executing this string by using PyRun_SimpleString(). >> >> >> >> Our concern is that if python has a method with no arguments we are able >> to execute it successfully >> >> >> >> But If Method takes parameters or arguments ,then how do we can pass >> values to that method and how can we execute it? >> >> >> >> Could you please provide the solution. >> >> >> >> Thanks and Regards, >> >> Lakshmi Narasaiah C, >> >> >> >> ___ >> BangPypers mailing list >> BangPypers@python.org >> http://mail.python.org/mailman/listinfo/bangpypers >> > ___ > BangPypers mailing list > BangPypers@python.org > http://mail.python.org/mailman/listinfo/bangpypers > ___ > BangPypers mailing list > BangPypers@python.org > http://mail.python.org/mailman/listinfo/bangpypers > -- cheers!!! Zubin ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Calling Python script from C++.
Hi Zubin, Deployment OS is RedHat Linux. Here is the python file : Hello.py Def sayHello(name): Print "Hello" + name sayHello(arg) and In c++ file, I am catching all the lines from the python file in string buffer and calling the PyRun_SimpleString(stringbuffer). It is working fine without passing any argument. But I want to send the argument to this python file from c++ file. Could you tell me how can I pass arguments to python file? Thanks, Lakshmi. -Original Message- From: bangpypers-bounces+lakshmi.chowdam=bt@python.org [mailto:bangpypers-bounces+lakshmi.chowdam=bt@python.org] On Behalf Of Zubin Mithra Sent: Thursday, February 25, 2010 5:11 PM To: Bangalore Python Users Group - India Subject: Re: [BangPypers] Calling Python script from C++. could you give us a few more details? the deployment OS? cheers!!! Zubin On Thu, Feb 25, 2010 at 12:51 PM, wrote: > Hi, > > > > We have a requirement of Calling Python script from C++. > > > > So, For this we are trying to pass entire python script(Script has both > method implementation and method calls are exist) as a string and > executing this string by using PyRun_SimpleString(). > > > > Our concern is that if python has a method with no arguments we are able > to execute it successfully > > > > But If Method takes parameters or arguments ,then how do we can pass > values to that method and how can we execute it? > > > > Could you please provide the solution. > > > > Thanks and Regards, > > Lakshmi Narasaiah C, > > > > ___ > BangPypers mailing list > BangPypers@python.org > http://mail.python.org/mailman/listinfo/bangpypers > ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Calling Python script from C++.
could you give us a few more details? the deployment OS? cheers!!! Zubin On Thu, Feb 25, 2010 at 12:51 PM, wrote: > Hi, > > > > We have a requirement of Calling Python script from C++. > > > > So, For this we are trying to pass entire python script(Script has both > method implementation and method calls are exist) as a string and > executing this string by using PyRun_SimpleString(). > > > > Our concern is that if python has a method with no arguments we are able > to execute it successfully > > > > But If Method takes parameters or arguments ,then how do we can pass > values to that method and how can we execute it? > > > > Could you please provide the solution. > > > > Thanks and Regards, > > Lakshmi Narasaiah C, > > > > ___ > BangPypers mailing list > BangPypers@python.org > http://mail.python.org/mailman/listinfo/bangpypers > ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Calling Python script from C++.
On Thu, 25 Feb 2010 07:21:15 - wrote: [...] > We have a requirement of Calling Python script from C++. [...] > So, For this we are trying to pass entire python script(Script > has both method implementation and method calls are exist) as a > string and executing this string by using PyRun_SimpleString(). [...] > Our concern is that if python has a method with no arguments we > are able to execute it successfully http://lmgtfy.com/?q=python+call+c might be of help. Regards, Gora ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers