integer type conversion problem/question

Faheem Mitha faheem at email.unc.edu
Sat Oct 9 17:11:23 EDT 2004



On Sat, 9 Oct 2004, Josiah Carlson wrote:

>> I'd looked at this earlier, but they didn't seem to have implemented a C
>> API. If there is one, I haven't been able to find it in
>> http://python.org/doc/2.3.4/api/api.html or anywhere else. I don't want to
>> import Python code into C/C++ even if that is possible. I think it is
>> easiest to work with a straight C/C++ library and interface it with
>> Python, assuming that I don't run into type conversion issues.
>
> So what you are saying is that you have some C code that needs to use
> random numbers, and that some higher-level Python module uses the output
> from your module.

Well, I want to the seed to be read and written to Python after each call 
to the C code. A modest desire, I think, but the out-of-the-box 
functionality for this in Python does not seem to exist yet.

>> A random number C module does exist in Python 2.3. On my system (Debian
>> Sarge) it is /usr/lib/python2.3/lib-dynload/_random.so. However, it is
>> probably not set up to be directly accessed from C/C++ code.
>
> I would suggest borrowing the necessary parts of _random.c, and call it
> good.  It is available via CVS in src/Modules .

Ok. I'll take a look at the sources. I wonderif I be able to use them 
without too much fuss in my C code, or whether will have I have to wrestle 
with all the Python C api stuff.
                                                                  Faheem.



More information about the Python-list mailing list