print format for binary representation

Rim rimbalaya at yahoo.com
Tue Jan 27 10:00:23 EST 2004


Hi,

>>> print '%x' % 54
36
>>> print '%b' % 54
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: unsupported format character 'b' (0x62) at index 1
>>>

No formating string for binary? There %x for hex. Would %b make sense
for bin? Is this worth a PEP?

How do I get 00110110 printed instead of the traceback?

Thanks,
-Rim



More information about the Python-list mailing list