Accessing C++ Data Structures, Containers from Python

After a little bit of digging, I’ve found out that vectors aren’t supported:

So vector is implemented by wrapping it into a template class, which I’ve found is PointerToArray. Adding, removing, reading , etc, all pertinent methods are documented here:
https://www.panda3d.org/reference/cxx/classPointerToArray.html#a7ae374aa0dea6ac59d8b185fcc27e713

One last question though, how would one access the data stored in the PointerToArray object from the python side, once it’s returned as a “block of raw data in a string”?

//C++:
	string return_potential_list()
	{
        group_of_ints.push_back(4);
		return group_of_ints.get_data();
	}

#Python:
potentialListOfInts=instTest.return_potential_list()

Is there any way to convert the returned string into a legible list of integers?

EDIT:

This worked for the conversion:

potentialListOfInts=instTest.return_potential_list()
intListByteString=bytes(potentialListOfInts, "utf8")
intList=list(intListByteString)

print(intList)
#This command yields: [4, 0, 0, 0]

I hope this helps people who are just venturing into mixing C++ and Python somehow.

Thanks.

2 Likes