From: Gardner P. <ga...@ne...> - 2006-01-08 04:42:14
|
Thank you, thank you, thank you! Ok, I changed example.i to what you have listed below, and tried this runme.py: # file: runme.py # test of std::map<std::string, std::string>; import example v =3D example.map_si() v['hi'] =3D 'no' v['bye'] =3D 'yes' print v.keys() print v.values() Executing "python runme.py" results in this output: ['bye', 'hi'] ('yes', 'no') This is SO COOL! I have an application in python that loads 5M lines from a 171MB file. Putting them into a dictionary with 5M entries uses up 1.5GB of ram. This SWIG will allow me to save a HUGE amount of memory. Thank you so much! - Gardner On 1/7/06, Marcelo Matus <mm...@ac...> wrote: > > As the std_map.i file says, std::map requires to instantiate std::pair. > > So you need to do: > > %module example > > %include "std_string.i" > %include "std_map.i" > > /* instantiate the required template specializations */ > %template() std::pair<std::string, std::string>; > %template(map_si) std::map<std::string, std::string>; > > > Marcelo > > > Gardner Pomper wrote: > > > Hi, > > > > I have a need for a C++ std::map<std::string,std::string> in my python > > program, so I download swig. I tried the following as an example to > > use std::map, but I get errors when I try to compile the generated > > .cxx file. Here is my example: > > > > /* File : example.i */ > > %module example > > > > %include "std_string.i" > > %include "std_map.i" > > > > /* instantiate the required template specializations */ > > %template(map_si) std::map<std::string, std::string>; > > > > I have tried the std_vector example in the python examples, and that > > worked. The command I run this with is: > > > > swig -c++ -python example.i > > make > > > > Here is the beginning of the output I get from that: > > > > make -f ../../Makefile CXXSRCS=3D'' SWIG=3D'../../../preinst-swig' \ > > SWIGOPT=3D'' TARGET=3D'example' INTERFACE=3D'example.i' python_cpp > > make[1]: Entering directory > > `/home/gardner/downloads/swig-1.3.27/Examples/python/std_map' > > ../../../preinst-swig -c++ -python example.i > > g++ -c -fpic example_wrap.cxx -DHAVE_CONFIG_H > > -I/usr/local/include/python2.4 -I/usr/local/lib/python2.4/config > > example_wrap.cxx: In function `const char* swig::type_name() [with Type > =3D > > std::string]': > > example_wrap.cxx:1596: instantiated from `static swig_type_info* > > swig::traits_info<Type>::type_info() [with Type =3D std::string]' > > > > I am running swig 1.3.27 on Quantian Linux (debian base, kernel > > 2.4.27) using gcc version 3.3.4. > > > > If anyone has an example of using an STL map from python, I would be > > very grateful! > > > > Thanks, > > > > - Gardner > > > > > |