[C++-sig] Re: [BPL] python::interpreter proposal
Dirk Gerrits
dirk at gerrits.homeip.net
Thu Jan 2 18:34:06 CET 2003
Bjorn Pettersen wrote:
>>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
> :-)
Hmm that's quite a showstopper. Perhaps a second enum parameter is
needed? Something like:
enum code_type
{ single_expression, single_statement, multiple_statements };
Not very nice IMHO so if anyone knows a way around it, please enlighten
me. ;)
Dirk Gerrits
More information about the Cplusplus-sig
mailing list