[Python-Dev] RFC: PEP 460: Add bytes % args and bytes.format(args) to Python 3.5 (original) (raw)

Victor Stinner victor.stinner at gmail.com
Tue Jan 7 19:14:56 CET 2014


2014/1/7 Stefan Behnel <stefan_ml at behnel.de>:

Victor Stinner, 06.01.2014 14:24:

struct.pack() is incomplete. For example, a number cannot be formatted as decimal and it does not support padding bytes string. Then what about extending the struct module in a way that makes it cover more use cases like these?

The idea of the PEP is to simply the portage work of Twisted and Mercurial developers. So the same code should work on Python 2 and Python 3.

Extending struct features would not help. This is like adding a new type or function in a third-party module, it requires also to modify the source code for Python 2. And struct.pack() does not even support "%s", the current format for bytes strings requires to specify the length of the string in the format.

Juraj Sukop asked me privately to support floating points in the PEP 460 for its PDF generator. Would you really like to add many features to the struct module? Padding, format as integer as decimal (maybe also binary, octal and hexadecimal), format floatting points as decimal, etc.?

Victor



More information about the Python-Dev mailing list