One trap I've hit sevreal times is: I think I copied an object, like a=b. But all Python does is make a & b point to the same object, so modifying b also changes a!
It's very painful to debug when this goes wrong.
The solution, I found, is to always use deepcopy() when you want to create a new object. But this isn't intuitive, and searching online doesnt give you the simple answer (unless you already know what the problem is)
So well explained! There are many articles like it, but this is the best one I ever read on this topic!
May I translate this article for my French students and publish the translated version on my website (with a link to the original content, of course)?
In any case, thank you
Yes, I give you the licence to translate, modify and distribute this article
Cool!
Any particular license? And if needed, what author name should I indicate?
No, just this licence for you. Use "Bite code" for the name, it's enough.
Enjoy
OK, thank you so much !
Nice.
One trap I've hit sevreal times is: I think I copied an object, like a=b. But all Python does is make a & b point to the same object, so modifying b also changes a!
It's very painful to debug when this goes wrong.
The solution, I found, is to always use deepcopy() when you want to create a new object. But this isn't intuitive, and searching online doesnt give you the simple answer (unless you already know what the problem is)
I should explain this in the article