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


Groups > comp.lang.python > #11450

Re: Help needed with using SWIG wrapped code in Python

From Stefan Behnel <stefan_ml@behnel.de>
Subject Re: Help needed with using SWIG wrapped code in Python
Date 2011-08-15 12:08 +0200
References <CANMJH-sXPQoNz9OYm1kJFJzZG8cXcMPdPd=wTPSwvpFVaTrwGQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.7.1313402896.27778.python-list@python.org> (permalink)

Show all headers | View raw


Vipul Raheja, 15.08.2011 10:08:
> I have wrapped a library from C++ to Python using SWIG. But I am facing
> problems while importing and using it in Python.
>
> $ python
> >>> import pyossimtest
> >>> import pyossim
> >>> a = ["Image1.png","Image2.png"]
> >>> b = pyossimtest.Info()
> >>> b.initialize(len(a),a)
> Traceback (most recent call last):
>    File "<stdin>", line 1, in<module>
>    File "pyossimtest.py", line 84, in initialize
>      def initialize(self, *args): return _pyossimtest.Info_initialize(self,
> *args)
> TypeError: in method 'Info_initialize', argument 3 of type 'char *[]'
>
> What does this error message imply? I have already handled char** as a
> special case in swig using typemaps.

I have little experience with SWIG, so I can't comment much on the problem 
at hand, but what I can do is to encourage you to use Cython instead. It's 
faster, easier to use and much more versatile for writing Python wrappers 
than SWIG. Basically, it provides you with the full power and flexibility 
of a programming language, whereas SWIG (like all automatic wrapper 
generators) is always limiting because it has its predefined ways of 
wrapping things, and if they don't fit, you're on your own fighting up-hill 
against it.

Stefan

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


Thread

Re: Help needed with using SWIG wrapped code in Python Stefan Behnel <stefan_ml@behnel.de> - 2011-08-15 12:08 +0200

csiph-web