If you're ever doing a foreach style iteration over a collection a la for object in objects:, object isn't a pointer or a reference, but a copy of what was in your collection. If you can remember this, you'll save yourself a couple hours of bashing your head on the wall and wondering where the hell your data was going
(
Read more... )
Comments 3
Now, you also have names that refer to these objects. There can be many different names that refer to the same object, and a name can refer to different objects at different times. When you perform assignment, or binding, you don't change the identity of any particular object, and you don't mutate any objects, you change which object a particular name points to. This is how the object variable in a loop like ( ... )
Reply
I had a collection of objects of class Field and subclasses thereof, and I was trying to do something like this:
for field in fields:
if field.name == 'foo': field = FieldSubclass(field.name)It's obvious to me now why that wouldn't have done any good ( ... )
Reply
Reply
Leave a comment