[C++-sig] Re: [BPL] python::interpreter proposal

Bjorn Pettersen BPettersen at NAREX.com
Thu Jan 2 18:16:20 CET 2003


> From: Dirk Gerrits [mailto:dirk at gerrits.homeip.net] 
> 
> Bjorn Pettersen wrote:
> >>From: Dirk Gerrits [mailto:dirk at gerrits.homeip.net]
> >>
> >>For the python::interpreter class that has been discussed
> >>here earlier I propose the following interface:
> > 
> > [...]
> > 
> >>object interpreter::run(object code_string);
> >>
> >>Run the Python code in the string
> >>extract<std::string>(code_string) with 
> >>this (sub-)interpreter and return the result.
> > 
> > 
> > Question... how are you going to distinguish calling PyRun_String
with 
> > Py_eval_input vs. Py_file_input? (the former only takes expressions,

> > the latter doesn't return a result...)
> 
> It doesn't? I wasn't aware of that.

No, it's undocumented.

> The PyRun_String docs say: "Returns the result of executing 
> the code as a Python object, or NULL if an exception was raised."
[...]

Try e.g. 

  PyObject* res = PyRun_String("5", Py_file_input, ns, ns);

and you'll see that res is pointing to None afterwards... Quite annoying
:-)

-- bjorn




More information about the Cplusplus-sig mailing list