dimanche 21 avril 2019

How to retrieve python pickled list in C++

Imagine a python script that creates a list of strings and then dumps it to a pickle file:

#!/usr/bin/env python3

import _pickle as cpickle

test_stringlist = ["this","is","a","test"]

cpickle.dump(test_stringlist, open("/path/to/test_pickle_file", "wb"))

Now what I want to achieve is to be able to itterate over this list in C++

So, in pseudo-code:

#include <iostream>

int main()
{

    // Pseudo code :

    std::vector<std::string> retrieved_vector;
    retrieved_vector = **I_need_some_magic_here**;

    for(std::string &text : retrieved_vector)
    {
         std::cout << text << std::endl;
    }

}

Expected output:

this
is
a
test

Aucun commentaire:

Enregistrer un commentaire