Python Jumpstart by Building 10 Apps Transcripts
Chapter: App 10: Movie Search App
Lecture: Introduction to the movie search app
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Application number 10, let's build a movie search app. Now it turns out we are going to put this movie search app
0:07
into a particularly unreliable environment, so we are going to have to do a lot of work to make sure our movie search app is durable
0:16
and it doesn't crash or behave too weirdly. Let's see how that's going to go. We are going to build an app that looks like this, standard header.
0:23
We are going to enter some text and this text is going to be the title of a movie. So, here we might say Top Gun,
0:31
and we'll try to go out to the internet and find information about movies with Top Gun in their title, but you can see in this case it said oh sorry,
0:38
the network happens to be down so no searching right now. But our app doesn't crash or give weird errors it just says hey, the network is down,
0:46
check your wi-fi or something like this. Then later we try again, search for Top Gun and boom, we get real live movie search results off the internet.
0:54
So it might sound like this is about searching movies, but really what we are going to focus on is error handling,
1:00
writing durable reliable applications. So we are going to focus on error handling,
1:06
the primary way to do this in Python is with exceptions, and try/except blocks, you'll see that we can have
1:13
multiple sort of error handling clauses in any particular situations, so there might be a host of reasons that our movie app doesn't work,
1:22
maybe the DNS server is down, maybe we entered a bad title, maybe the wi-fi is down, maybe the other server actually gave a 500,
1:31
maybe malformed data came back, so we can actually catch different errors and give different messages back.
1:38
We might want to tell the users something different if the data that came back was malformed, rather than if the network was not connected.
1:46
Right, so we'll use multiple what are called except blocks to do this and that will allow us to differentiate errors based on the type of the error,
1:53
and ultimately, we are going to talk about writing reliable code and you also see how to raise errors and exceptions
2:00
not just catch them because we are going to throw some to sort of make our app particularly unreliable.