C API: Getting PyObject by name
Thomas Jollans
thomas at jollybox.de
Thu Sep 30 15:24:32 EDT 2010
On Thursday 30 September 2010, it occurred to pbienst to exclaim:
> Hi,
>
> I'm embedding Python in a C app.
>
> Say I do the following:
>
> PyRun_SimpleString("a = 1")
>
> Is there then a way to get access to the PyObject corresponding to a,
> only making use in C of the fact that it's called "a"?
>
> I've searched through the API docs, but I couldn't really find what I
> was looking for.
No. Not as such. But you could use PyRun_String, or PyRun_StringFlags. You
could then access the globals object, but I ask you, why would you want to
bind the object to a name in the first place? Use the fact that PyRun_String
returns a reference to the result of an expression!
More information about the Python-list
mailing list