Learning Python Quotes

Rate this book
Clear rating
Learning Python Learning Python by Mark Lutz
3,191 ratings, 4.01 average rating, 177 reviews
Open Preview
Learning Python Quotes Showing 1-30 of 114
“As usual, though, if you find yourself running into a wall, stop running into a wall!”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Python’s OOP nature makes it ideal as a scripting”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Because writing teaches writers to write,”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“This search order is called the new-style MRO for “method resolution order” (and often just MRO for short when used in contrast with the DFLR order). Despite the name, this is used for all attributes in Python, not just methods.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“In fact, type itself derives from object, and object derives from type, even though the two are different objects — a circular relationship that caps the object model and stems from the fact that types are classes that generate classes:”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Of course, as I’ve pointed out numerous times in this book, type checking is usually the wrong thing to do in Python programs (we code to object interfaces, not object types), and the more general isinstance built-in is more likely what you’ll want to use in the rare cases where instance class types must be queried.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“getattr employs the inheritance search protocol, and some of the names we’re listing here are not stored on the instance itself.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“mix-in classes are the class equivalent of modules”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“In a sense, mix-in classes are similar to modules: they provide packages of methods for use in their client subclasses.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“In new-style classes (optional in 2.X and standard in 3.X), the attribute search is usually as before, but in diamond patterns proceeds across by tree levels before moving up, in a more breadth-first fashion. This order is usually called the new-style MRO, for method resolution order, though it’s used for all attributes, not just methods.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“everything is a “first class” object in Python —”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Factories can be a major undertaking in a strongly typed language such as C++ but are almost trivial to implement in Python.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Technically speaking, classes belong in the callable objects category too, but we normally call them to generate instances rather than to do actual work —”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Although it’s possible to emulate true access controls in Python classes, this is rarely done in practice, even for large systems.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“within a class statement only, any names that start with two underscores but don’t end with two underscores are automatically expanded to include the name of the enclosing class at their front.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“You normally shouldn’t do this, though — it’s not the Python way.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Third, and perhaps most subtle, the display methods also have the potential to trigger infinite recursion loops in rare contexts — because some objects’ displays include displays of other objects, it’s not impossible that a display may trigger a display of an object being displayed, and thus loop. This is rare and obscure enough to skip here, but watch for an example of this looping potential to appear for these methods in a note near the end of the next chapter in its listinherited.py example’s class, where __repr__ can loop.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Python programmers are able to write large OOP frameworks and applications without private declarations — an interesting finding about access controls in general that is beyond the scope of our purposes here.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“If you wish to use this method, you can avoid loops by coding instance attribute assignments as assignments to attribute dictionary keys. That is, use self.__dict__['name'] = x, not self.name = x; because you’re not assigning to __dict__ itself, this avoids the loop:”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“This method is a bit trickier to use, though, because assigning to any self attributes within __setattr__ calls __setattr__ again, potentially causing an infinite recursion loop (and a fairly quick stack overflow exception!).”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“attribute access (a.k.a. qualification)”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“any function that contains a yield statement is turned into a generator function.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“for calls iter, which calls __iter__”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“We’ll see one use case for __new__ when we study metaclasses in Chapter 40; though rare, it is sometimes also used to customize creation of instances of immutable types.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Technically, instance creation first triggers the __new__ method, which creates and returns the new instance object, which is then passed into __init__ for initialization.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Python “best practice” rule of thumb is to use docstrings for functional documentation (what your objects do) and hash-mark comments for more micro-level documentation (how arcane bits of code work).”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“In fact, within Python, instance and class objects are mostly just dictionaries with links between them.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“That is, a class is a local scope and has access to enclosing local scopes, but it does not serve as an enclosing local scope to further nested code.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Normally we create instance attributes by assigning them in class __init__ constructor methods, but this isn’t the only option.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Inheritance-tree climbing happens only on attribute reference, not on attribute assignment.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming

« previous 1 3 4