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 returns ValueError: zero length field name in format. Is there a different way doing simple formated conversions for python2.6

0

1 Answer 1

1

Use the format() 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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy 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.