Does PyModule_GetDict return information about class method variables?

Marc 'BlackJack' Rintsch bj_666 at
Fri Aug 10 15:19:00 CEST 2007

On Fri, 10 Aug 2007 05:54:03 -0700, MD wrote:

> On Aug 10, 12:43 am, Marc 'BlackJack' Rintsch <bj_... at> wrote:
>> class A(object):
>>     def foo(self):
>>         bar = 42
>> The local name `bar` only exists if `foo()` is called on an instance of `A`.
>    Thanks for your reply. I am calling my extension function from the
> class method itself. So at that point the variable does exist. I am
> puzzled why PyModule_GetDict is not able to access the variable even
> though it does exist at that point.

It does not exist in the module or the function object but on the stack. 
Let's go to C again:

void baz(void);

void foo(void)
    int bar = 42;

How do you get from `baz()` the value of `foo()`\s local `bar`?  Other
than ugly non portable stack trickery!?

Why don't you just give the object as argument to your C function? 
Wanting to poke around in the callers name space is code smell.  Don't do

	Marc 'BlackJack' Rintsch

More information about the Python-list mailing list