#100DaysOfCode in Python Transcripts
Chapter: Days 79-81: Basic Database Access with SQLite3
Lecture: Pulling data with SELECT

Login or purchase this course to watch this video and the rest of the course contents.
0:00 All right, now that we have our lovely table with Mike, Bob, and myself in it, and our very realistic addresses,
0:09 let's actually print some of that data out. So we're going to do that within the Python shell. Again, import sqlite3, getting tedious by now.
0:19 So, we will run our connection, con equals sqlite3.connect. addressbook.db. 'Kay, c = con.cursor to get our cursor.
0:38 Now to print the actual data within the database, we need to put this into a for loop, okay? Just bear with me, because we're going to
0:46 iterate over these three rows, okay? So, the way we do that, is we go for row in c.execute. We're going to select data.
1:01 Now what data were we going to select? We're going to select everything from our details table, all right, so for row in c.execute.
1:10 Select all from details. What next? Well, once it's got the row, we want to print the row. And that's it. And there are our three lines.
1:25 You've got these, the formatting's a bit off, it's actually taking that data, or the literal, the tuple for that, for that row, you know?
1:34 So it doesn't look that great. So to actually make that look a little bit better, let's just bring that back up to save me some time.
1:43 We can actually choose which column to view, so we can go print row... Zero. Julian, Bob, Mike. And once we have this sort of information,
2:00 you can start to pop a few strings together, you know, start making sentences from these, these sorts of database pulls.
2:09 So let's do one really quickly here. And there we go. So Julian lives at 123 Fake Street, blah blah blah, and his phone number X, okay?
2:20 And that's the sort of manipulation we can do by pulling the data out of the database.


Talk Python's Mastodon Michael Kennedy's Mastodon