Paddy McCarthy added the comment:

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 <rep...@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!

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16580>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to