From Python to c++

Marco Aschwanden PPNTWIMBXFFC at spammotel.com
Tue Mar 21 14:42:56 EST 2006


This is actually a c++ problem. Got no satisfying answer on comp.lang.c++.  
Maybe you can help better because I know, there are many c++-converts ;).

Suppose you've got the following list (first line has field names, second  
line has types and any row after is data):

csv = "name,age,place\nstring,int,string\nMac,25,Zurich\nMike,55,Oslo"

and you would like to turn it into a dictionary:

parsed = {
  "name":["Mac", "Mike"],
  "age":[25, 55],
  "place":["Zurich", "Oslo"]
}

A trivial task in Python. In C++ it is cumbersome. I was thinking to put  
the parsed data into a map:

map<string, vector<???> >

I have no problem with the key (string) but the value (vector) needs to be  
of varying type. I think C++-STL does not allow what I want.

The following proposal is useless:

[...]
A simple solution, make two maps:

std::map<std::string, std::vector<std::string> > result_name;
std::map<std::string, std::vector<int> >         result_age;
[...]

I want to build the map of lists dynamically - it can have many fields or  
just one... and I would like to have simple interface (as Python offers).

- I cannot import python into the c++ environment (Borland Developer 2006)  
and I know no one who was able to.

- I cannot write (*sigh*) the app in Python.

Any suggestions are very welcome!


Regards,
Marco (Forced to code in c++ again let me estimate the simplicity of  
python)





More information about the Python-list mailing list