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 61-90 of 114
“Again, though, they may be created by assignment anywhere a reference to the instance appears, even outside the class statement. Normally, all instance attributes are initialized in the __init__ constructor method; that way, later method calls can assume the attributes already exist.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Class attributes can also be created, though, by assigning attributes to the class anywhere a reference to the class object exists — even outside the class statement.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“In a sense, a module is like a single-instance class, without inheritance, which corresponds to an entire file of code.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Although we can store functions in dictionaries, too, using them to process implied instances is nowhere near as natural and structured as it is in classes.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“the attributes of a namespace object are usually implemented as dictionaries, and class inheritance trees are (generally speaking) just dictionaries with links to other dictionaries.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“On the other hand, you might decide to use operator overloading if you need to pass a user-defined object to a function that was coded to expect the operators available on a built-in type like a list or a dictionary.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Common practice dictates that overloaded operators should work the same way that built-in operator implementations do.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Although we could implement all class behavior as method functions, operator overloading lets objects be more tightly integrated with Python’s object model.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“As we get deeper into Python classes, though, keep in mind that the OOP model in Python is very simple; as we’ve seen here, it’s really just about looking up attributes in object trees and a special function argument.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“polymorphism means that the meaning of an operation depends on the object being operated on.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Because using classes well requires some up-front planning, they tend to be of more interest to people who work in strategic mode (doing long-term product development) than to people who work in tactical mode (where time is in very short supply).”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“In general, you can define collector modules that import all the names from other modules so they’re available in a single convenience module.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Best practice in all Pythons recommends listing all your imports at the top of a module file; it’s not required, but makes them easier to spot.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“PYTHONPATH and .pth files offer more permanent ways to modify the path — the first per user, and the second per installation.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Notice that compilation happens when a file is being imported. Because of this, you will not usually see a .pyc byte code file for the top-level file of your program, unless it is also imported elsewhere — only imported files leave behind .pyc files on your machine.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“As usual in Python, it’s important to understand fundamental principles like those illustrated in the prior section. Python’s “batteries included” approach means you’ll usually find precoded options as well, though you still need to know the ideas underlying them to use them properly.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“that’s why we need recursion here: the number of nested loops is arbitrary, and depends on the length of the sequence permuted:”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“remember that generator functions simply return objects with methods that handle next operations run by for loops at each level, and don’t produce any results until iterated; and”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“As the prior section suggested, these classes usually return their objects directly for single-iteration behavior, or a supplemental object with scan-specific state for multiple-scan support.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“By yielding results as it goes, the walker does not require its clients to wait for an entire tree to be scanned.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“In other words, the age-old acronym KISS still applies: Keep It Simple — followed either by a word that is today too sexist (Sir), or another that is too colorful for a family-oriented book like this...”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“If you have to translate code to statements to understand it, it should probably be statements in the first place.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“At the same time, code like that of the prior section may push the complexity envelope more than it should — and, frankly, tends to disproportionately pique the interest of those holding the darker and misguided assumption that code obfuscation somehow implies talent. Because such tools tend to appeal to some people more than they probably should, I need to be clear about their scope here. This book demonstrates advanced comprehensions to teach, but in the real world, using complicated and tricky code where not warranted is both bad engineering and bad software citizenship. To repurpose a line from the first chapter: programming is not about being clever and obscure — it’s about how clearly your program communicates its purpose. Or, to quote from Python’s import this motto: Simple is better than complex.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Python has a host of tools that most would consider functional in nature, which we enumerated in the preceding chapter — closures, generators, lambdas, comprehensions, maps, decorators, function objects, and more.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“as this little function isn’t needed elsewhere, it was written inline as a lambda.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“In general, simple is better than complex, explicit is better than implicit, and full statements are better than arcane expressions.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Cohesion: each function should have a single, unified purpose. When designed well, each of your functions should do one thing — something you can summarize in a simple declarative sentence. If that sentence is very broad (e.g., “this function implements my whole program”), or contains lots of conjunctions (e.g., “this function gives employee raises and submits a pizza order”), you might want to think about splitting it into separate and simpler functions.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“In Pythons 3.3 and 2.7, you can get help for a module you have not imported by quoting the module’s name as a string — for example, help('re'), help('email.message') — but support for this and other modes may differ across Python versions.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“One of the first questions that bewildered beginners often ask is: how do I find information on all the built-in tools?”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming
“Interestingly, the iteration protocol is even more pervasive in Python today than the examples so far have demonstrated — essentially everything in Python’s built-in toolset that scans an object from left to right is defined to use the iteration protocol on the subject object.”
Mark Lutz, Learning Python: Powerful Object-Oriented Programming