Re: python commmand line params from c++



On 30 Jun 2005 07:52:04 -0700
"Wesley Henwood" <wesleyhenwood@xxxxxxxxxxx> wrote:

> What is the proper way to pass command line parameters to a python
> script called from C++? I'm tryng this:

Have you tried PySys_SetArgv?

> path = "c:\\someDir\\someScript.py param1 param2 param3";
> PyRun_SimpleFile(PyFile_AsFile( PyFile_FromString( path, "r")),
> "someScript.py");

This code looks strange: you open file and create Python file object
from its descriptor (PyFile_FromString), then get descripto back
(PyFile_AsFile) to pass it to PyRun_SimpleFile. Why don't you just use
C fopen function?

> I'm getting a "format error someScript.py, line 1" when the code is
> executed.
>
> Note: The strange appearannce of the 3 python function calls nested is
> not a bug, but required to prevent a run-time error.

I believe it's due to PyFile_FromString failing to open non-existent
file. You must check return value of it.

--
Denis S. Otkidach
http://www.python.ru/ [ru]
.



Relevant Pages

  • Re: Dictionary instantiation?
    ... Python for a few days. ... #Function to remove entries with '' in the ... csv_list = list#Convert the open file to list format ... The concept of instantiation is ...
    (comp.lang.python)
  • Re: How to execute a file with (---x--x--x) Permissions and I am not the
    ... $ python backup_all.py>> log.txt ... python: can't open file ... read in the files to execute them. ... So these Python scripts? ...
    (Ubuntu)
  • Overloaded Constructors?!?
    ... was a little bit strange to obtain an answer... ... written it and, since it is a useful widget to have in a wxPython GUI, I ... while pure Python code should be. ...
    (comp.lang.python)
  • Re: newbie write to file question
    ... * You may want to put the heart of the code in a separate function or if ... that seemed strange to me since I think you were doing this ... Remember python defines blocks by indentation. ...
    (comp.lang.python)
  • Re: how to creating html files with python
    ... I need to create html files through python and add some data from the database. ... The only strange thing here is that you think this is a strange ...
    (comp.lang.python)