How to create an instance of a python class from C++

Stefan Behnel stefan_ml at behnel.de
Wed Mar 12 13:10:03 EDT 2014


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





More information about the Python-list mailing list