dabeaz-course/practical-python

Typo in 2.3

Closed this issue · 1 comments

Hi,
Assuming the web version is up to date and this hasn't already been rectified, in the 2.3 section (link),
in the C-style formatting subsection, the note says

>>> b'%s has %n messages' % (b'Dave', 37)
b'Dave has 37 messages'
>>>

The %n is incorrect; it leads to a ValueError. I checked the printf function in C and the python documentation, this isn't a valid format character. My guess is that either %d or %i would be the appropriate choice.
On the same topic, the python doc says (for python 3.x) that for bytes, %s is deprecated but will not be removed (ref, see note 6 in the subsection). %b is the preferred version (%s acts as an alias for %b).

To summarize, I would change the previous code in the following manner:

>>> b'%b has %d messages' % (b'Dave', 37)
b'Dave has 37 messages'
>>>

Thanks for the course and happy holidays!
Stay safe!

Fixed.