My first book, Learn Python 3 the Hard Way, very casually covered scanners in Exercise 48, but now we’re going to get more formal. I’ll explain the concept behind scanning text, how that relates to regular expressions, and how you can create a little scanner for a tiny piece of Python code.
Let’s use the following Python code as an example to start the discussion:
def hello(x, y): print(x + y) hello(10, 20)
You’ve been training in Python for a while, so your brain most likely can read this code quickly, but do you really understand what it is? When I (or someone else) taught you Python I had you memorize all the “symbols.” The
() characters are each symbols, but there needs to be a way for Python to process ...