On May 7, 4:03 pm, Joel Bender <[EMAIL PROTECTED]> wrote:
> > Python 3.0 has such a formatting operation, but Python 2.x does not.  
> > However it's not hard to write.
>
> Indeed.  Refraining from using named lambdas:
>
>      >>> def bin(x):
>      ...     return ''.join(x & (1 << i) and '1' or '0' for i in
>      ...         range(7,-1,-1))
>      ...
>      >>> bin(12)
>      '00001100'
>      >>> bin(63)
>      '00111111'
>
> It would be nice to have str(x, 2) like int(x, 2), but there are bigger
> fish in pond.

+1 str( x, base ) +1
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to