[Python-3000] PEP 3101 str.format() equivalent of '%#o/x/X'?
Eric Smith
eric at trueblade.com
Tue Jul 1 01:46:55 CEST 2008
Eric Smith wrote:
> Barry?
By which I meant "Barry, what's your opinion?", not "who is Barry?"
(which I well know). Geez, I write the worst email sometimes.
ERic.
>
> Guido van Rossum wrote:
>> I'd check with Barry, but given that .format() is a new feature in
>> these releases anyway and this is a pretty small addition to one tiny
>> bit of code I would have been okay with it if I were release manager.
>>
>> On Mon, Jun 30, 2008 at 11:36 AM, Eric Smith
>> <eric+python-dev at trueblade.com> wrote:
>>> I finally have some cycles for this. Is it okay to add '#' to hex,
>>> bin, and
>>> oct for str.format(), even though it's now after the beta?
>>>
>>> Eric.
>>>
>>> Guido van Rossum wrote:
>>>> Of course.
>>>>
>>>> On Fri, May 30, 2008 at 12:23 PM, Eric Smith
>>>> <eric+python-dev at trueblade.com> wrote:
>>>>> Guido van Rossum wrote:
>>>>>> I'd be fine with adding '#' back to the formatting language for
>>>>>> hex and
>>>>>> oct.
>>>>> And bin, I assume?
>>>>>
>>>>>> On Thu, May 29, 2008 at 5:45 PM, Eric Smith
>>>>>> <eric+python-dev at trueblade.com> wrote:
>>>>>>> wesley chun wrote:
>>>>>>>> On 5/29/08, Eric Smith <eric+python-dev at trueblade.com> wrote:
>>>>>>>>> Marcin 'Qrczak' Kowalczyk wrote:
>>>>>>>>>> Except that it works incorrectly for negative numbers.
>>>>>>>> wow, that is a great point. i didn't think of this either. it
>>>>>>>> makes
>>>>>>>> it very inconvenient (see below) and makes it more difficult to say
>>>>>>>> we've completed replaced the '%' operator.
>>>>>>>>
>>>>>>>>
>>>>>>>>> I can't really think of any other way that doesn't involve
>>>>>>>>> converting
>>>>>>>>> the
>>>>>>>>> number to a string and then operating on that, just to get the
>>>>>>>>> sign.
>>>>>>>> here's one way of doing it without converting to a string first
>>>>>>>> (it's
>>>>>>>> ugly
>>>>>>>> too):
>>>>>>>>
>>>>>>>>>>> i = -45
>>>>>>>>>>> '{0}0x{1:x}'.format('-' if i < 0 else '', abs(i))
>>>>>>>> '-0x2d'
>>>>>>> Agreed, ick!
>>>>>>>
>>>>>>>> thx for putting it (back) in,
>>>>>>> I didn't say I would, I said I would if a decision was reached
>>>>>>> :) I'd
>>>>>>> like
>>>>>>> to see some more consensus, and I hope that Talin (the PEP author)
>>>>>>> chimes
>>>>>>> in.
>>>>>>>
>>>>>>> Eric.
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> Python-3000 mailing list
>>>>>>> Python-3000 at python.org
>>>>>>> http://mail.python.org/mailman/listinfo/python-3000
>>>>>>> Unsubscribe:
>>>>>>> http://mail.python.org/mailman/options/python-3000/guido%40python.org
>>>>>>>
>>>>>>>
>>>>>>
>>>>
>>>>
>>>
>>
>>
>>
>
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe:
> http://mail.python.org/mailman/options/python-3000/eric%2Bpython-dev%40trueblade.com
>
>
More information about the Python-3000
mailing list