|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Iterator for Vector of objects returns copy of Object (Python)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 |
|
|
Re: Iterator for Vector of objects returns copy of Object (Python)On Thu, 1 May 2008, Jose Luna wrote: > 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. I'm not sure I understand. Is tmp a member of the C++ class, or is it something you add to the Python object by that assignment? If it's just being added to the Python object, of course it won't affect the underlying C++ object (where would the data go?) an the print statement will fail. Josh ------------------------------------------------------------------------- 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 |
|
|
|
| Free Forum Powered by Nabble | Forum Help |