New vs Old Style Python Classes in C Extensions?

Jeff Rush jeff at taupro.com
Sat Jan 27 06:11:58 EST 2007


While I have a reasonable understanding of the differences in new-style versus 
old-style classes, tonight while working a C extension module I realized I 
don't know how to indicate which style my C extension module should appear as.

I'm following the Python docs for extended modules, but it doesn't say in 
there anyplace I can find which style I'm creating.  My clue that something 
was wrong is when this:

from cextension import Context

class MyContext(Context):

     def __init__(self):
         super(Context, self).__init__()

repeatedly and reliably failed with a corrupted C data structure, while this:

class MyContext(Context):

     def __init__(self):
         Context.__init__()

worked without any problems.  As I understand it, the former uses new-style 
semantics while the latter uses old-style, and -thats- when I realized I have 
no idea which my C extension implemented.

Any enlightenment?

-Jeff




More information about the Python-list mailing list