On Thu, 09 Aug 2007 19:34:37 -0700, MD wrote: > I have a variable which is defined inside a class method. When I > call PyModule_GetDict on the module containing this class, the > dictionary doesn't contain any information about this variable. Is > this expected behavior? If so, what options do I have to access this > variable from my Python C extension.
You can't access names in methods because they don't exist until you call the method. It's just like local variables in C. Consider: void foo(void) { int bar = 42; } Here `bar` does not exist until you call `foo()` and it disappears as soon as the function returns. It's the very same situation in Python: class A(object): def foo(self): bar = 42 The local name `bar` only exists if `foo()` is called on an instance of `A`. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list