Skip to content

Previous: 23 - Imports | Table of Contents | Next: 25 - Do a Project


24 - Reading Code

If you have stuck with Python up to this point, congratulations! You have learned the basics of Python scripting. Everything you have learned up to now has been an exercise to get you familiar with the syntax of Python as well as a few basic principles of programming and computer science. I mentioned when we introduced functions that there are a few things that are common to all programming languages. There are only a few more concepts common to many programming languages that we have not yet covered in Python. However, you now know enough to understand the majority of the language.

Your Reading Assignment

For this lesson, do the following steps:

  • Go to a website that hosts open source code such as github.com.
  • Search the website for Python code you can read. It really doesn't matter what exactly you read, just don't read anything that is marked as Python 2 (it will just confuse you).
  • Read one or two scripts and see if you can figure out what the scripts are doing and how they are doing them.

It is possible you will run into some things what we have not covered yet. Do not worry about understanding the code perfectly, just do your best to understand it. If you cannot follow some code at all, try another script until you can get a rough idea of what a script is doing. As you read, feel free to reference sections we have covered so far or search the Internet to help you understand. (Remember to type "Python" and then write what you are looking for into any search engine.)

Pay attention to how the code is documented as you do this. Is the documentation helpful in understanding the code?

As you work, take notes on things you notice about the code. How can you apply what you see in other's code to your own code?

Like all of these lessons, what you put in to this exercise is what you will get out of it. If you put forth the effort and really try to understand the code you will gain some valuable insight into how real code is written.

Hone Your Skills

  • Do this exercise for another Python third-party library. You can find links to many libraries on PyPI. While you do the exercise think about this: Could you write your own module? How? (Note: We will go into detail on this later.)

Previous: 23 - Imports | Table of Contents | Next: 25 - Do a Project