None is wrong, it depends on how much control you want to have and the last one works also on objects without __iter__. Keep in mind that vars works with the object with iter as well.
Hi. In general case, your solution is better and cleaner than mine. I was so excited to have found the solution (it was a work task) that I forgot to mention, that the object is a huge legacy object and I needed just a few of its attributes and .update(obj) is a legacy line I have no control over. I'll update the post soon, thanks for the comment.
Hi Maria, neat trick, you made me think about it and I found a few alternatives if you don't care about whitelisting:
and even easier one without
__iter__
:None is wrong, it depends on how much control you want to have and the last one works also on objects without
__iter__
. Keep in mind that vars works with the object with iter as well.Hi. In general case, your solution is better and cleaner than mine. I was so excited to have found the solution (it was a work task) that I forgot to mention, that the object is a huge legacy object and I needed just a few of its attributes and .update(obj) is a legacy line I have no control over. I'll update the post soon, thanks for the comment.
Ahah you see, then your solution is more apt than mine ;-)
I just gave you two other options that are useful in case you cannot modify the source code of the class.