classification
Title: Add center_char attribute to str type
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: lovi, paul.moore, rhettinger, steve.dower, steven.daprano, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2019-12-13 12:42 by lovi, last changed 2019-12-14 01:35 by rhettinger. This issue is now closed.

Messages (4)
msg358328 - (view) Author: Lovi (lovi) Date: 2019-12-13 12:42
I think Python3.9 needs to add the center_char attribute which means the center character of strings to string type, such as the center_char of '12345' is '1' and the center_char of 'abcd' is 'bc'.
msg358331 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2019-12-13 13:29
What you mean by "center_char" is not clear to me.

How is "bc" a character? It looks like two characters to me.

How is "1" the center char of "12345"? It looks like the leftmost character to me.

Once you have explained what "center_char" does, could you explain how it will be useful?
msg358370 - (view) Author: Lovi (lovi) Date: 2019-12-14 01:25
Sorry, I made a mistake.

The center char of '12345' is '3' and the center char of 'abcd' is '' because it doesn't have the most central character.

In my opinion, with center_char, when you need the center character of a string you can get it directly with str.center_char instead of tedious index and calculation.
msg358371 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-12-14 01:35
Thank you for the suggestion, but this proposal isn't broadly useful enough to warrant adding a new method.
History
Date User Action Args
2019-12-14 01:35:29rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg358371

resolution: rejected
stage: resolved
2019-12-14 01:25:56lovisetmessages: + msg358370
2019-12-13 13:29:00steven.dapranosetnosy: + steven.daprano
messages: + msg358331
components: + Library (Lib), - Windows
2019-12-13 12:42:53lovicreate