[issue14694] Option to show leading zeros for bin/hex/oct

2012-05-01 Thread Eric V. Smith

Eric V. Smith  added the comment:

I agree with Mark.

This can also be done slightly more efficiently with plain format():

>>> format(324, "016b")
'000101000100'
>>> format(324, "016o")
'0504'
>>> format(324, "016x")
'0144'

And with either format() or str.format(), you can add the appropriate prefix:
>>> format(324, "#016b")
'0b0101000100'
>>> format(324, "#016o")
'0o000504'
>>> format(324, "#016x")
'0x000144'

I don't see ever adding all of the possible options to bin(), etc.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14694] Option to show leading zeros for bin/hex/oct

2012-05-01 Thread Mark Dickinson

Mark Dickinson  added the comment:

I'm rejecting this: the functionality is already there in str.format, and 
there's little to be gained by adding another way to do it.

--
nosy: +eric.smith
resolution:  -> rejected
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14694] Option to show leading zeros for bin/hex/oct

2012-04-29 Thread Mark Dickinson

Changes by Mark Dickinson :


--
stage:  -> needs patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14694] Option to show leading zeros for bin/hex/oct

2012-04-29 Thread Mark Dickinson

Changes by Mark Dickinson :


--
versions: +Python 3.3 -Python 2.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14694] Option to show leading zeros for bin/hex/oct

2012-04-29 Thread Mark Dickinson

Mark Dickinson  added the comment:

-1. str.format already does this quite effectively;  I don't see a real need to 
complicate the bin, hex and oct signatures.

>>> '{:016b}'.format(324)
'000101000100'
>>> '{:016o}'.format(324)
'0504'
>>> '{:016x}'.format(324)
'0144'

--
nosy: +mark.dickinson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14694] Option to show leading zeros for bin/hex/oct

2012-04-29 Thread endolith

New submission from endolith :

Suggestion: Add an option to bin/hex/oct functions to format binary output with 
a minimum fixed width, including leading zeros.  Also might be useful for hex 
and oct.

Currently, bin(18) produces '0b10010'

with this change, something like bin(18, foo=8) would produce '0b00010010'


Examples of people wanting this:

http://stackoverflow.com/questions/3258330/converting-from-hex-to-binary-without-losing-leading-0s-python

http://stackoverflow.com/questions/1002116/can-bin-be-overloaded-like-oct-and-hex-in-python-2-6

http://stackoverflow.com/a/1425558/125507

https://www.linuxquestions.org/questions/programming-9/in-python-printing-leading-zero-for-hex-numbers-0-through-f-719426/

--
components: Interpreter Core
messages: 159623
nosy: endolith
priority: normal
severity: normal
status: open
title: Option to show leading zeros for bin/hex/oct
type: enhancement
versions: Python 2.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com