Exercise 32. Scanners
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 def and () characters are each symbols, but there needs to be a way for Python to process ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access