Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19001 > unrolled thread
| Started by | Stefan Behnel <stefan_ml@behnel.de> |
|---|---|
| First post | 2012-01-15 11:24 +0100 |
| Last post | 2012-01-15 11:24 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: defining class and subclass in C Stefan Behnel <stefan_ml@behnel.de> - 2012-01-15 11:24 +0100
| From | Stefan Behnel <stefan_ml@behnel.de> |
|---|---|
| Date | 2012-01-15 11:24 +0100 |
| Subject | Re: defining class and subclass in C |
| Message-ID | <mailman.4764.1326623066.27778.python-list@python.org> |
Daniel Franke, 14.01.2012 22:15: > I spent some days and nights on this already and my google-fu is running out. > I'd like to implement the equivalent of this Python code in a C-extension: > > >>> class A(object): > .... pass > >>> class B(A): > .... pass > >>> A > <class '__main__.A'> > >>> B > <class '__main__.B'> > >>> B.__bases__ > (<class '__main__.A'>,) > > However, loading my C-code (quoted below) I get: > > >>> import ca > >>> ca > <module 'ca' from 'ca.so'> > >>> ca.ca > <type 'ca.ca'> > > Here I'd expect "<class 'ca.ca'>" instead?! You already got the response (and found for yourself) that this is normal. CPython makes a distinction between classes defined the Python way and extension types, the latter of which you define in your code. As a general advice: if your primary interest is in implementing some kind of functionality, instead of just learning about the bits and pieces of CPython's C-API, you may want to take a look at Cython. It makes writing efficient C extension modules fast and easy, especially when it comes to class hierarchies and similarly things. Stefan
Back to top | Article view | comp.lang.python
csiph-web