Title: Tkinter: deprecate the split() method
Type: Stage: resolved
Components: Tkinter Versions: Python 3.9
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: serhiy.storchaka
Priority: normal Keywords: patch

Created on 2019-10-04 15:33 by serhiy.storchaka, last changed 2019-10-08 11:37 by serhiy.storchaka. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 16584 merged serhiy.storchaka, 2019-10-04 15:45
Messages (2)
msg353948 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-10-04 15:33
The tkapp.split() method has weird behavior. It splits a string recursively, so the type of items and the depth of nesting depends on spaces in string values. For example:

>>> import tkinter
>>> root = tkinter.Tcl()
>>>'Hello "Good bye"')
('Hello', ('Good', 'bye'))

It may work as you meant in some cases (if items at the same level either all have spaces or all do not have spaces), but return unexpected  result for untested cases. It is more robust to use the tkapp.splitlist() method, which split exactly one level and always returns a tuple of strings. It can be used recursively if you need nested lists.

>>>'Hello "Good bye"')
('Hello', 'Good bye')
>>> [ for x in'Hello "Good bye"')]
[('Hello',), ('Good', 'bye')]
msg354186 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-10-08 11:31
New changeset d05b000c6bcd39dba4f4b2656e45954802649562 by Serhiy Storchaka in branch 'master':
bpo-38371: Tkinter: deprecate the split() method. (GH-16584)
Date User Action Args
2019-10-08 11:37:58serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-10-08 11:31:44serhiy.storchakasetmessages: + msg354186
2019-10-04 15:45:22serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request16175
2019-10-04 15:33:41serhiy.storchakacreate