Think Python: How to Think Like a Computer Scientist
Pipes Most operating systems provide a command-line interface, also known as a shell. Shells usually provide ...
Writing Modules Any file that contains Python code can be imported as a module. For example, suppose you ...
tricky, so the safest thing to do is restart the interpreter and then import the module again. ...
Debugging When you are reading and writing files, you might run into problems with whitespace. These errors ca ...
Glossary persistent: Pertaining to a program that runs indefinitely and keeps at least some of its data ...
pipe object: An object that represents a running program, allowing a Python program to run commands and ...
Exercises Exercise 14-1. Write a function called sed that takes as arguments a pattern string, a replacem ...
...
Chapter 15. Classes and Objects At this point you know how to use functions to organize code and built-in ...
Programmer-Defined Types We have used many of Python’s built-in types; now we are going to define a n ...
Every object is an instance of some class, so “object” and “instance” are interchangeable. But in this cha ...
Attributes You can assign values to an instance using dot notation: >>> blank.x = 3.0 >>> blank.y = ...
You can pass an instance as an argument in the usual way. For example: def print_point(p): pri ...
Rectangles Sometimes it is obvious what the attributes of an object should be, but other times you have to m ...
Figure 15-2. Object diagram. ...
Instances as Return Values Functions can return instances. For example, find_center takes a Rectangle as an a ...
Objects Are Mutable You can change the state of an object by making an assignment to one of its attributes. For exa ...
Copying Aliasing can make a program difficult to read because changes in one place might have unexpected eff ...
Figure 15-3. Object diagram. For most applications, this is not what you want. In this example, invokin ...
Debugging When you start working with objects, you are likely to encounter some new exceptions. If you try to ...
«
9
10
11
12
13
14
15
16
17
18
»
Free download pdf