This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paddy3118
Recipients asvetlov, docs@python, ezio.melotti, paddy3118
Date 2012-12-10.05:57:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <50C57977.7020506@googlemail.com>
In-reply-to <1355050536.14.0.511880853298.issue16580@psf.upfronthosting.co.za>
Content
On 09/12/2012 10:55, Ezio Melotti wrote:
> Ezio Melotti added the comment:
>
> 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 http://docs.python.org/3/library/functions.html#all, 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 http://docs.python.org/3.3/library/stdtypes.html#int.bit_length 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.
>
> ----------
> keywords: +easy
> stage:  -> needs patch
> versions: +Python 2.7, Python 3.2, Python 3.4
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue16580>
> _______________________________________
>
The second example looks great. I like the dual use for testing too and 
will try and remember both the next time I find I have ireas about the 
documentation.

Thanks guys. It's appreciated!
History
Date User Action Args
2012-12-10 05:57:39paddy3118setrecipients: + paddy3118, ezio.melotti, asvetlov, docs@python
2012-12-10 05:57:39paddy3118linkissue16580 messages
2012-12-10 05:57:39paddy3118create