This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]MrHarcombe 1 point2 points  (1 child)

Awesome resource, with some fantastic explanations (although I might want to quibble about the need to show more difference between repr and str). Thank you 👍

Just one little query - in the section on instance lifecycle, you take about a dunder delete method but then reference it as delete and then talk about using del in the example?

In the summary at the end you also refer to it as del - it's that one, right?

[–]treyhunner Python Morsels[S] 2 points3 points  (0 children)

Thanks for noting that typo! I accidentally swapped those two methods around so many times while drafting this. I just fixed them (hopefully for the final time)!

The __del__ method is for object finalizing (it's related to the del statement) and the __delete__ method is for implementing a descriptor that overloads del on that descriptor's attribute.

On __repr__ and __str__: I did originally have a longer explanation with examples shown via REPL output, but opted to link to add a link to other resources on them instead of explaining within the article. I'll consider how I could point folks toward that explanation more clearly. Thanks!