Accessing Python variables in an extension module

Diez B. Roggisch deets at nospam.web.de
Mon Jul 16 15:49:54 CEST 2007


MD wrote:

> Hi Alex,
>    Thanks for your reply. It was exactly what I was looking for. Two
> additional questions
> 1) Is there anyway to find out which modules a variable belongs to
> when I have only its name (and its not qualified with the complete
> name like module.varname)

No.

> 2) Is there anyway to find the type of the object in C using something
> like a switch statement? I was looking for something like this
>    switch type(object) {
>       STRING: "This is a string object";
>               break;
>       INTEGER: "This is an integer object";
>               break;
>       BOOLEAN: "This is a boolean object";
>       .........
>       .........
>       }
> I don't want to run all the C Py***_Check functions on the object.
> Something like the switch statement above will lead to nice and clean
> code.

In python, 

obj.__class__.__name__

should work. I don't know what to write in C to accomplish that, but it
can't be too hard. Factor it away in a function.

Diez



More information about the Python-list mailing list