« Return to Thread: Iterator for Vector of objects returns copy of Object (Python)

Iterator for Vector of objects returns copy of Object (Python)

by Jose Luna-2 :: Rate this Message:

Reply to Author | View in Thread

I am using the std::vector template to contain a set of objects.

%include "std_vector.i"
namespace std {
   %template(vector_cgv) vector<CGVertex>;
};

Everything works fine when I bring the vector into Python, but when I iterate through the vector it returns a copy of the object instead of the object itself.  For example, if vertices is my vector:

for vertex in vertices:
    vertex.tmp = 1
print vertex[0].tmp

This code will cause the following error: "AttributeError: tmp".  The tmp attribute assigns fine, but it's assigning it to a copy of the vertex object, so when I try to go back and access that attribute it isn't there.  (I've confirmed this through further testing.) I realize that I could simply build a new list of objects, but that would be inefficient and I'm hoping for a more elegant solution.

Thanks in advance,

JLuna






      ____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

 « Return to Thread: Iterator for Vector of objects returns copy of Object (Python)

LightInTheBox - Buy quality products at wholesale price