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 SQLAlchemy Basics Working with SQLAlchemy Cleaning Data

Andras Andras
Andras Andras
7,941 Points

App returns strange list of items.

When I run the code:

if name == "main": Base.metadata.create_all(engine) # app() add_csv() for book in session.query(Book): print (book)

It gives a strange result. Why?

PS C:\prog\Python\Eel\SQLite book database> python app.py <models.Book object at 0x000002479B5F3F10> <models.Book object at 0x000002479E507220> <models.Book object at 0x000002479E507280> <models.Book object at 0x000002479E507040> <models.Book object at 0x000002479E507010> <models.Book object at 0x000002479E506F80> <models.Book object at 0x000002479E506EF0> <models.Book object at 0x000002479E506E60> <models.Book object at 0x000002479E506DD0> <models.Book object at 0x000002479E506950>

Caleb Kemp
Caleb Kemp
12,754 Points

I only looked at this for a second, but I saw you wrote

name == "main":

I think that might supposed to be __name__ == "main":

Here is a link to the video about using dunder main. I know jb30 is experienced in Python, he might have some good ideas if that wasn't the problem. Hope that helps.

@craskan Markdown formats __name__ == "__main__" without the backticks as name == "main", so that is not an issue.

This question looks like a duplicate by the same poster so I tried answering the previous one instead.

Caleb Kemp
Caleb Kemp
12,754 Points

That makes sense, I looked at the answer you put on the other post and I think it's exactly right, kind of how you might have to overwrite the "toString" method in some other languages. jb30 thanks for looking into it.

Andras Andras this is the video where the teacher covers that and 5:18 is where the teacher covers the __repr__ method specifically.

1 Answer

Basically it is giving you the position in memory of the item,(like when you park the car, it is telling you where the car is parked) in memory, check how you are calling the object, I think the method used is not the correct one, check for the way your method is being called.