Python Tricks Quotes
Python Tricks: A Buffet of Awesome Python Features
by
Dan Bader1,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)”
― Python Tricks: A Buffet of Awesome Python Features
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)”
― 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)”
― Python Tricks: A Buffet of Awesome Python Features
iterator = iter(repeater)
while True:
try:
item = next(iterator)
except StopIteration:
break
print(item)”
― 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.”
― Python Tricks: A Buffet of Awesome Python Features
― 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.”
― Python Tricks: A Buffet of Awesome Python Features
― 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()”
― Python Tricks: A Buffet of Awesome Python Features
― 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'}”
― Python Tricks: A Buffet of Awesome Python Features
― Python Tricks: A Buffet of Awesome Python Features
“There should be one—and preferably only one—obvious way to do it.”
― Python Tricks: A Buffet of Awesome Python Features
― Python Tricks: A Buffet of Awesome Python Features
“Tim Peters’ Zen of Python.”
― Python Tricks: A Buffet of Awesome Python Features
― 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.”
― Python Tricks: A Buffet of Awesome Python Features
― Python Tricks: A Buffet of Awesome Python Features
