YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Accessing a Website with Code - Programming Foundations with Python

Get Embed Code
7 Languages

Showing Revision 4 created 05/25/2016 by Udacity Robot.

  1. So here we are, back with our code. Now, the
  2. only new stuff that I have added to the code
  3. thus far, is this function called, check_profanity, by the way,
  4. this function is empty for now. It takes in, one argument,
  5. or one piece of information, which is the text we
  6. actually want to check for profanity. Now, I know there
  7. is this module in Python called, URL lib, which helps
  8. us get information from the internet. It, has a function called,
  9. URL open, which takes in a link to a website.
  10. So here, I'm going to give it the full link,
  11. to the the what do you love website. [SOUND] And
  12. add to that the text we actually want to check for
  13. profanity. [SOUND] Now, this function URL open. Is going to
  14. help us make a connection, to this website. So, I'm going
  15. to call this, [SOUND] connection. Now I recognize that you
  16. may not be able to read the entire line of code
  17. that we've written here, so I'm going to temporarily, put
  18. in a return statement there. So you can read the
  19. whole line of code. And then I'm going to restore
  20. the code. Okay, let's continue. Now, I want us to
  21. notice, that this function URL open, is quite similar to
  22. the other function that we have used in this program,
  23. which is open. Open, helps us read contents from a
  24. file on our computer. URL open on the other hand,
  25. helps open a connection to a website on the internet. Then we
  26. can do things with that connection. Things like, read a response from
  27. that website. [SOUND] I'm going to call this response, output, and then print
  28. the output. After I've done that, [SOUND] I will close the connection.
  29. So now, it's time for us to call this
  30. function check_profanity, and I will do that after I have
  31. successfully read the text from a file on my
  32. computer. [SOUND] So, let me add code to call the
  33. function, check_profanity, and to it, I will pass in
  34. the contents that we previous read from the file. I
  35. am going to save our program. Now if all
  36. goes well, the read_text function, will read the contents from
  37. the movie_quotes file, and then the check_profanity function,
  38. will check that text for curse words. Let me
  39. run my program and oh, it seems like, I forgot to import URL lib. So let me go
  40. back to the code and add that to the very top. [SOUND] There it is. Let me
  41. save my program, and run again. And this time,
  42. the program worked and the programs response is false,
  43. which means that the movie quotes, have no
  44. curse words in them. Now, if I go back
  45. to my movie quotes file. And change just one
  46. word, let me save this file. And run my
  47. code one more time. Now the response changes to
  48. true, which means that there was a curse word
  49. in our movie codes file. Alright, so it seems
  50. like we're getting very close to finishing this code.
  51. But before we do, [SOUND] I want us to figure out. How
  52. Python knows about this think URL lib and URL open, lets find out.