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


Groups > comp.lang.python > #21601

Re: Instantiate a python class object in C

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'python.': 0.04; 'classes.': 0.05; 'function,': 0.07; 'subject:object': 0.07; 'working:': 0.07; 'python': 0.08; 'extension.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:python': 0.10; 'demo:': 0.16; 'from:addr:behnel.de': 0.16; 'from:addr:stefan_ml': 0.16; 'from:name:stefan behnel': 0.16; 'magic.': 0.16; 'translates': 0.16; 'extension': 0.17; 'instance': 0.18; 'header:In-Reply-To:1': 0.22; 'asked': 0.24; 'defined': 0.24; 'stefan': 0.24; 'code.': 0.26; 'code': 0.26; 'figure': 0.26; 'function': 0.27; "i'm": 0.28; 'second': 0.28; 'class': 0.29; 'definition': 0.30; 'good.': 0.32; 'there': 0.33; "can't": 0.33; 'header:User-Agent:1': 0.33; 'header:X-Complaints- To:1': 0.34; 'especially': 0.34; 'to:addr:python-list': 0.35; 'received:org': 0.36; 'but': 0.37; 'another': 0.37; 'should': 0.38; 'easier': 0.38; 'received:de': 0.39; 'goes': 0.39; 'to:addr:python.org': 0.40; "you'll": 0.61; 'your': 0.61; 'efficient': 0.62; 'anything.': 0.71; 'hand,': 0.76; '"demo"': 0.84; 'working,': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Stefan Behnel <stefan_ml@behnel.de>
Subject Re: Instantiate a python class object in C
Date Wed, 14 Mar 2012 15:13:05 +0100
References <500e1575-78e7-45aa-8fc3-78427bbe917c@l7g2000vbw.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host fw-snc-frn5-de01.fw.telefonica.de
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2
In-Reply-To <500e1575-78e7-45aa-8fc3-78427bbe917c@l7g2000vbw.googlegroups.com>
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.635.1331734407.3037.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1331734407 news.xs4all.nl 6951 [2001:888:2000:d::a6]:40633
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:21601

Show key headers only | View raw


Dids, 14.03.2012 14:46:
> Apologies if this was asked before, I couldn't find anything.
> 
> I have a class defined in a python file:
> for example:
> 
> class demo:
>       [ class definition goes here]
> 
> I'm writing a C extension.
> In the first function, I take an instance of the "demo" class and do
> my magic. It's working, all is good.
> 
> What I can't figure out is how to create a second C function that
> returns a new instance to the "demo" class to python.
> There must a be tutorial somewhere, but I can't find anything. I do
> not want to define a new python class in C.
> 
> Another example:
>    This is working:
>         demo_obj1 = demo()
>         my_C_extension.function_1( demo_obj1 )  //working, all good.
> 
>    This I can't figure out how to do:
>         new_demo_obj = my_C_extension.function_2()

You should consider giving Cython a try. It will allow you to write normal
Python code for your C extension that it translates to efficient C code.
This is much easier than writing all of this by hand, especially when it
comes to classes. It will also optimise the code for you, so that you'll
often end up with faster code than what you'd manually write.

Stefan

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Instantiate a python class object in C Dids <didierblanchard@gmail.com> - 2012-03-14 06:46 -0700
  Re: Instantiate a python class object in C Stefan Behnel <stefan_ml@behnel.de> - 2012-03-14 15:13 +0100
    Re: Instantiate a python class object in C Dids <didierblanchard@gmail.com> - 2012-03-14 07:28 -0700

csiph-web