implicit conversion

B

Benjamin Schmeling

Hi,

I am working on exposing a bigint class to python. Now I've got the
problem that methods which take an bigint as
an parameter do not accept Python longs.

For example:
import _PythonLiDIA
x=123L;
c=_PythonLiDIA.bigint();
_PythonLiDIA.gcd(c,x);


Traceback (most recent call last):
File "test.py", line 132, in ?
_PythonLiDIA.gcd(a,x);
Boost.Python.ArgumentError: Python argument types in
_PythonLiDIA.gcd(bigint, long)
did not match C++ signature:
gcd(LiDIA::bigint, LiDIA::bigint)

I don't know how to achieve implicit conversion at this point, turning an
long automatically into an bigint. The other way round, turning an bigint
into long can be realized by defining __long__.

Can someone help me please?

Benjamin
 
A

Alex Martelli

Benjamin Schmeling said:
I don't know how to achieve implicit conversion at this point, turning an
long automatically into an bigint. The other way round, turning an bigint
into long can be realized by defining __long__.

Perhaps adding to your bigint class a constructor (not declared as
``explicit'', if you're coding C++) which accepts as its argument a
python long might help...?


Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top