Author ezio.melotti
Recipients asvetlov, docs@python, ezio.melotti, paddy3118
Date 2012-12-09.10:55:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Usually we add plain Python equivalents when they are simple enough that the code equivalent is as understandable as the prose or more (see for example, or the itertools functions you mentioned).
For this case I think it would help if you presented an equivalent function, e.g.:

def to_bytes(n, length, order):
    if order == 'little':
        return bytes((n >> i*8) & 0xff for i in range(length))
    elif order == 'big':
        return bytes((n >> i*8) & 0xff for i in reversed(range(length)))

or even:

def to_bytes(n, length, order):
    indexes = range(length) if order == 'little' else reversed(range(length))
    return bytes((n >> i*8) & 0xff for i in indexes)

This is also done for just above to/from_bytes, so it might be a good addition.
If this is done, the equivalent function can also be added to the test suite, so we can verify that it's indeed equivalent.
Date User Action Args
2012-12-09 10:55:36ezio.melottisetrecipients: + ezio.melotti, paddy3118, asvetlov, docs@python
2012-12-09 10:55:36ezio.melottisetmessageid: <>
2012-12-09 10:55:36ezio.melottilinkissue16580 messages
2012-12-09 10:55:35ezio.melotticreate