Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'url:sourceforge': 0.03; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:create': 0.09; 'subject:instance': 0.09; 'subject:How': 0.10; 'python': 0.11; 'def': 0.12; 'suggest': 0.14; 'posted': 0.15; '(also': 0.16; 'correct)': 0.16; 'from:addr:behnel.de': 0.16; 'from:addr:stefan_ml': 0.16; 'from:name:stefan behnel': 0.16; 'python3.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:class': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'stefan': 0.19; 'header :User-Agent:1': 0.23; 'certainly': 0.24; 'simpler': 0.24; 'looks': 0.24; 'this:': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; "doesn't": 0.30; 'code': 0.31; 'class': 0.32; 'figure': 0.32; 'subject:from': 0.34; "can't": 0.35; 'tool': 0.35; 'received:84': 0.35; 'really': 0.36; 'to:addr:python-list': 0.38; 'rather': 0.38; 'does': 0.39; 'bill': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'helps': 0.61; 'more': 0.64; 'mar': 0.68; 'obvious': 0.74; 'heavy': 0.81; '2014,': 0.84; 'examples.': 0.84; 'lifting': 0.84; 'received:arcor-ip.net': 0.84; 'received:pools .arcor-ip.net': 0.84; 'safer,': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Stefan Behnel Subject: Re: How to create an instance of a python class from C++ Date: Wed, 12 Mar 2014 18:10:03 +0100 References: <0ab424e9-3a3f-4111-9f41-ff50ce73d70d@googlegroups.com> <8AEE6BCA-0F61-4F9E-A18B-13DB283DC134@barrys-emacs.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: dslb-084-056-051-157.pools.arcor-ip.net User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 In-Reply-To: <8AEE6BCA-0F61-4F9E-A18B-13DB283DC134@barrys-emacs.org> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1394644217 news.xs4all.nl 2915 [2001:888:2000:d::a6]:53011 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68288 Barry Scott, 11.03.2014 22:37: > On 5 Mar 2014, at 00:14, Bill wrote: >> I can't figure out how to create an instance >> of a python class from 'C++': > > Why not use pycxx from http://sourceforge.net/projects/cxx/? > > This lib does all the heavy lifting for you for both python2 and python3. > Has docs and examples. Yes, tool support definitely helps here. I was going to suggest Cython (also for obvious reasons), where the code that the OP posted would look like this: def RegisterClass(class_decl): an = type(class_decl)() print(an.description()) return 0 Clearly substantially simpler than the posted C code (and certainly safer, faster and more correct) - although that doesn't really help me much with understanding what the intention of this code is, looks rather weird... Stefan