Chapter 8. 7 modules, methods, classes, and objects: Getting Modular
Figure 8-1.
Your code is growing in size and complexity. As that happens you need better ways to abstract, to modularize, to organize your code. You’ve seen that functions can be used to group lines of code together into bundles you can reuse over and over. And you’ve also seen that collections of functions and variables can be placed into modules so that they can be more easily shared and reused. In this chaper we’ll revisit modules and learn how to use them even more effectively (so you’re all ready to share your code with others) and then we’re going to look at the ultimate in code reuse: objects. You’re going to see that Python objects are all around you, just waiting to be used.
Figure 8-2.
Cubicle conversation
Figure 8-3.
Greg: That’s easy; just ship him analyze.py. He can just import it and call the compute_readability function. Done!
Frank: Totally. Modules are just Python files; just ship it.
Joe: I don’t think that is quite right. I know we’ve said a file is just a module and all that, and we’ve certainly used import, but I think there is more to it than that.
Greg: Like what?
Joe: Well, for ...
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