Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19001

Re: defining class and subclass in C

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'below)': 0.05; 'cpython': 0.05; 'bits': 0.07; 'distinction': 0.07; 'python': 0.08; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'things.': 0.12; 'advice:': 0.16; 'from:addr:behnel.de': 0.16; 'from:addr:stefan_ml': 0.16; 'from:name:stefan behnel': 0.16; '>>>': 0.18; 'loading': 0.18; 'extension': 0.21; 'header:In-Reply- To:1': 0.22; 'pieces': 0.23; 'similarly': 0.23; 'defined': 0.24; 'stefan': 0.24; 'code': 0.25; 'classes': 0.26; 'code.': 0.26; 'expect': 0.26; 'import': 0.27; 'pass': 0.28; 'class': 0.29; '(and': 0.29; 'equivalent': 0.30; 'implementing': 0.32; 'modules': 0.32; 'implement': 0.32; 'header:User-Agent:1': 0.33; 'instead': 0.33; 'to:addr:python-list': 0.33; 'daniel': 0.34; 'received:84': 0.34; 'spent': 0.34; 'latter': 0.34; 'header:X-Complaints-To:1': 0.34; 'running': 0.35; 'especially': 0.35; 'response': 0.35; 'however,': 0.35; 'received:org': 0.37; 'some': 0.38; 'primary': 0.38; "i'd": 0.39; 'define': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'got': 0.40; 'your': 0.61; 'efficient': 0.61; 'kind': 0.62; 'here': 0.64; 'interest': 0.65; 'nights': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Stefan Behnel <stefan_ml@behnel.de>
Subject Re: defining class and subclass in C
Date Sun, 15 Jan 2012 11:24:12 +0100
References <2921241.kWnIB6QQbB@silence>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host dslb-084-056-000-204.pools.arcor-ip.net
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111220 Thunderbird/9.0
In-Reply-To <2921241.kWnIB6QQbB@silence>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4764.1326623066.27778.python-list@python.org> (permalink)
Lines 37
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1326623066 news.xs4all.nl 6922 [2001:888:2000:d::a6]:35297
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:19001

Show key headers only | View raw


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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: defining class and subclass in C Stefan Behnel <stefan_ml@behnel.de> - 2012-01-15 11:24 +0100

csiph-web