Python Tricks Quotes

Rate this book
Clear rating
Python Tricks: A Buffet of Awesome Python Features Python Tricks: A Buffet of Awesome Python Features by Dan Bader
1,096 ratings, 4.43 average rating, 101 reviews
Open Preview
Python Tricks Quotes Showing 1-9 of 9
“class Indenter:
def __init__(self):
self.level = 0

def __enter__(self):
self.level += 1
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self.level -= 1

def print(self, text):
print(' ' * self.level + text)”
Dan Bader, Python Tricks: A Buffet of Awesome Python Features
“repeater = BoundedRepeater('Hello', 3)
iterator = iter(repeater)
while True:
try:
item = next(iterator)
except StopIteration:
break
print(item)”
Dan Bader, Python Tricks: A Buffet of Awesome Python Features
“Assertions are meant to be internal self-checks for your program. They work by declaring some conditions as impossible in your code. If one of these conditions doesn’t hold, that means there’s a bug in the program.”
Dan Bader, Python Tricks: A Buffet of Awesome Python Features
“You see, the proper use of assertions is to inform developers about unrecoverable errors in a program. Assertions are not intended to signal expected error conditions, like a File-Not-Found error, where a user can take corrective actions or just try again.”
Dan Bader, Python Tricks: A Buffet of Awesome Python Features
“Python’s bytecode disassembler lives in the dis module that’s part of the standard library. So we can just import it and call dis.dis()”
Dan Bader, Python Tricks: A Buffet of Awesome Python Features
“Take a moment to reflect on the following dictionary expression and what it will evaluate to: >>> {True: 'yes', 1: 'no', 1.0: 'maybe'}”
Dan Bader, Python Tricks: A Buffet of Awesome Python Features
“There should be one—and preferably only one—obvious way to do it.”
Dan Bader, Python Tricks: A Buffet of Awesome Python Features
“Tim Peters’ Zen of Python.”
Dan Bader, Python Tricks: A Buffet of Awesome Python Features
“If your format strings are user-supplied, use Template Strings to avoid security issues. Otherwise, use Literal String Interpolation if you’re on Python 3.6+, and “New Style” String Formatting if you’re not.”
Dan Bader, Python Tricks: A Buffet of Awesome Python Features