python-distilled icon indicating copy to clipboard operation
python-distilled copied to clipboard

6.6 line_receiver must be initialized with r.send(None)

Open marcoemorais opened this issue 2 years ago • 0 comments

Thank you for writing this book! Python Distilled is a worthy replacement for Python Essential Reference.

In section 6.6 the code snippet that demonstrates the enhanced generator line_receiver is missing the initialization step r.send(None).

In other words change

from

r = line_receiver()
r.send(b'hello')
r.send(b'world\nit ')
r.send(b'works!')
r.send(b'\n')

to

r = line_receiver()
r.send(None)  # Missing in book.
r.send(b'hello')
r.send(b'world\nit ')
r.send(b'works!')
r.send(b'\n')

marcoemorais avatar Sep 04 '23 22:09 marcoemorais