[New-bugs-announce] [issue23624] str.center inconsistent with format "^"

Vedran Čačić report at bugs.python.org
Tue Mar 10 06:53:55 CET 2015


New submission from Vedran Čačić:

Look at this:

    >>> format("ab", "^3"), "ab".center(3)
    ('ab ', ' ab')
    >>> format("abc", "^4"), "abc".center(4)
    ('abc ', 'abc ')

I'm sure you agree this is inconsistent. As far as I can see, format relies on // (flooring) behaviour when dividing remaining space by 2, while .center relies on round (ROUND_HALF_EVEN) behaviour. One of them should be changed to match the other.

As far as I can see, documentation (in neither case) says nothing about how _exactly_ strings are centered when there is an odd number of fill characters, so I would interpret this as: we can change either. (My preference is for .center to be changed, but this is not so important. Consistency is important.)

----------
messages: 237729
nosy: Vedran.Čačić
priority: normal
severity: normal
status: open
title: str.center inconsistent with format "^"
type: behavior
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23624>
_______________________________________


More information about the New-bugs-announce mailing list