Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Using Databases in Python Gettin' CRUD-y With It Delete An Entry

Drew Butcher
Drew Butcher
33,160 Points

delete entry notation

Before I saw the way Kenneth Love typed delete entry

entry.delete_instance()

I tried

Entry.delete_instance(entry)

It seem to work! Are they the same?

Your method, i.e. Entry.delete_instance(entry) is better in terms of the hierarchical consistency..

1 Answer

Stephen Link
Stephen Link
3,685 Points

They can be the same. I haven't been able to dig out the code for the Entry class so I won't say for sure that they are the same. But they could be. If you think about it "entry" is an instance of the Entry class. So entry.delete_instance() is just calling the delete_instance method on that particular instance of the Entry class while Entry.delete_instance(entry) is going back to the class itself, calling the delete_instance method, and passing in the entry as the thing to be deleted. Depending on how that method is written (and as I said I haven't pulled out the code so I don't know for sure) these two things can indeed result in the same behavior.