get PyObject* knowing its string name

M

Mr.M

I think this sounds like a stupid question, but I searched the C/Api doc
and google but I wasn't able to find any hint:

how can I retrive PyObject pointer if I only know it's name?

What I'd like to do is something like this:

Code:
PyObject* obj = PyFindWhatImLookingFor("w.z.y.x");

Of course if I know that w is a module, z is a class and so on I can
search w dictionary than z members than...

But I wonder if there is a way to retrive without knowing what w.z.y.x
means.

Thank you,

Luca.
 
R

Robert Kern

I think this sounds like a stupid question, but I searched the C/Api doc
and google but I wasn't able to find any hint:

how can I retrive PyObject pointer if I only know it's name?

What I'd like to do is something like this:

Code:
PyObject* obj = PyFindWhatImLookingFor("w.z.y.x");

Of course if I know that w is a module, z is a class and so on I can
search w dictionary than z members than...

But I wonder if there is a way to retrive without knowing what w.z.y.x
means.

There is probably a clever/careful way to do it, but most systems that do this
just separate the package/module parts from the object parts:

"w:z.y.x"

Import the module part, then getattr() your way down the object part.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top