1

In python2.7"{:010b}".format(25) would return'0000011001' giving a 10 bit binary string representation of the number 25. In python2.6 the same command returnsValueError: zero length field name in format. Is there a different way doing simple formated conversions for python2.6

BenMorel's user avatar
BenMorel
37k52 gold badges208 silver badges339 bronze badges
askedApr 16, 2013 at 16:28
Richard's user avatar
0

1 Answer1

1

Use theformat() function, it's easier (no need for the template placeholder parts, only the formatter string is needed):

format(25, '010b')

but you ran into a simplification in Python 2.7, where you don't have to specify the positional parameter. The 2.6 equivalent is:

"{0:010b}".format(25)
answeredApr 16, 2013 at 16:36
Martijn Pieters's user avatar
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.