[C++-sig] How to export arrays from C(++) to python using boo st

Shukla, Nitin (Export) nitin.shukla at pw.utc.com
Tue Feb 10 17:24:02 CET 2004


Hi,

I have downloaded the Numeric Utility Interface but couldn't build and 
test the demonstration num_util on my Windows system. The readme document 
which came with the download says that it was only tested on Mandrake 
Linux v8.2, with gcc-3.2, boost-1.30.0, and Python-2.2.2 libraries. 

I have Windows 2000 system with MinGW gcc-3.2.3, boost-1_31_0 and 
Python-2.3.2 libraries. Will it work on the above system. Do I need 
something else to compile and build the demonstration program num_util.

Nitin


-----Original Message-----
From: Xavier WARIN(Compte LOCAL) - I23

Hi,

If your python array are Numerical Python array, you can use the Numeric 
Utility Interface

http://www.eos.ubc.ca/research/clouds/software/pythonlibs/

Hope it helps.

Xavier

Kirsebom Nikolai wrote:
>>-----Original Message-----
>>From: Shukla, Nitin (Export) [mailto:nitin.shukla at pw.utc.com]
>>Hi,
>>
>>I am working on an application where an array of ints and 
>>floats are to 
>>exported from C++ to Python using boost::python. 
>>
>>As I am newbie to boost python, I couldn't find any documentation or 
>>working example that satisfies the above requirement. Can 
>>someone help 
>>me out??
>>
> 
> 
> Had similar need some time ago (fetching / setting BLOB values in
database).
> Ended up making conversion to/from file in C++ code (MFC) and using the
> python Array module to import.  Hope info below (which is fragments of
> working code) is of any use.  The class DLBlob is a class providing needed
> methods to set/get byte array.  Python code would supply the filename to
be
> used.
> 
> Nikolai
> 
> //C++ CODE
> int PyElement::Blob2File(CString fileName)
> {
> 	DLBlob blob = GetBlobValue();
> 	if (!blob.IsEmpty()) {
> 		unsigned char * b = blob.GetBuffer();
> 		CFile theFile(fileName, CFile::modeCreate | CFile::modeWrite
> | CFile::typeBinary);
> 		theFile.Write(b, blob.Length());
> 		theFile.Close();
> 		return blob.Length();
> 	}
> 	return 0;
> }
> 
> int PyElement::File2Blob(CString fileName)
> {
> 	CFile theFile(fileName, CFile::modeRead | CFile::typeBinary);
> 	DWORD fileSize = theFile.GetLength();
> 	void *s = ::malloc(fileSize+1);
> 	DWORD count = theFile.Read(s, fileSize);
> 	theFile.Close();
> 
> 	DLBlob blob(count);
> 	blob.InsertBytes(s, count, 0);
> 	SetBlobValue(blob);
> 	return (int)count;
> }
> 
> int PyElement::BlobSize()
> {
> 	DLBlob blob = GetBlobValue();
> 	if (!blob.IsEmpty()) {
> 		return blob.Length();
> 	}
> 	return 0;
> }
> 
> BOOST_PYTHON_MODULE(CElement)
> {
> 	class_<PyElement>("Element")
> 		.def("Blob2File", &PyElement::Blob2File)
> 		.def("File2Blob", &PyElement::File2Blob)
> 		.def("BlobSize", &PyElement::BlobSize)
> 	;
> }
> 
> 
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
> 
> 


_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig




More information about the Cplusplus-sig mailing list