[issue33040] Make itertools.islice supports negative values for start and stop arguments for sized iterable object
TitanSnow <tttnns1...@gmail.com> added the comment: Now I have thought about it and realized that it's not suitable for islice. But there's still a common use case to drop some elements from the beginning or ending of a iterable, which is also a main reason why I wanted islice to support negative values of start and stop. So how about adding two functions ``drop_first`` and ``drop_last`` to do such things. They can be implemented like this, in which way they support arbitrary iterators:: def drop_first(iterable, n=1): for _ in range(n): next(iterable) for e in iterable: yield e def drop_last(iterable, n=1): dq = deque() for _ in range(n): dq.append(next(iterable)) for e in iterable: dq.append(e) yield dq.popleft() -- ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue33040> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12345] Add math.tau
Change by TitanSnow <tttnns1...@gmail.com>: -- pull_requests: +5816 ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue12345> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue32917] ConfigParser writes a superfluous final blank line
TitanSnow <tttnns1...@gmail.com> added the comment: For the case of sequential writes to the same file, I think it’s a invalid use case. The file can be created or modified by user or other applications, breaking the assume of ConfigParser. It’s better to have a method to merge two ConfigParser objects then writes it into the file at one time. -- ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32917> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue32917] ConfigParser writes a superfluous final blank line
TitanSnow <tttnns1...@gmail.com> added the comment: > But I didn't thought that a superfluous final blank line causes any problems. > What software has a problem with it? Currently I have not found a program that has problem with the superfluous final blank line, and I think there won’t be. > Removing the final blank line can harm the readability in the case of > sequential writes to the same file Sorry that I have not thought about this. In this way, the prev patch that adds two new parameters might be better. > Remind me, why do we care about that extra blank line? Well, though it seems that that extra blank line won’t cause any problem, it does not look nice I think, and is different with INI files written by other applications. -- ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32917> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue33040] Make itertools.islice supports negative values for start and stop arguments for sized iterable object
New submission from TitanSnow <tttnns1...@gmail.com>: ``islice()`` does not support negative values for start or stop, which does not matter for plain iterators. However, for some cases, we have a sized iterable object which is not subscriptable, using ``islice()`` makes code ugly:: d = OrderedDict() for i in range(10): d[i] = i dv = d.keys() # dv is a KeysView which is a sized iterable # now I wanna get a slice of dv which does not contain the last element islice(dv, len(dv) - 1) As it shows, I have to use ``len(dv)`` to get its length. For sized iterable objects, ``islice()`` could support negative values for start or stop. In this way, the above code can be written like this:: islice(dv, -1) For iterable objects which is not sized, it could still be not supported:: islice(iter(range(10)), -1) raises a ValueError as its original behavior. -- components: Library (Lib) files: islice.patch keywords: patch messages: 313517 nosy: tttnns priority: normal severity: normal status: open title: Make itertools.islice supports negative values for start and stop arguments for sized iterable object type: enhancement Added file: https://bugs.python.org/file47475/islice.patch ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue33040> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue32917] ConfigParser writes a superfluous final blank line
TitanSnow <tttnns1...@gmail.com> added the comment: If we treat the original behavior as a bug, it’s much easier to write a patch that just changes the default behavior and never outputs a final blank line. I have looked through the testsuite of it. It seems that the original author had knew the final blank line and treat it as expect result. I’m not sure about it. -- Added file: https://bugs.python.org/file47474/simple.patch ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32917> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue32917] ConfigParser writes a superfluous final blank line
TitanSnow <tttnns1...@gmail.com> added the comment: I’m afraid of breaking the backward compatibility. -- ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32917> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue32930] [help][webbrowser always opens new tab. I want to open in the same tab]
TitanSnow <tttnns1...@gmail.com> added the comment: Yes, I think so. Maybe, in a web application, to achieve this, the way is to use a GUI library then use its web view widget. -- ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32930> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue32930] [help][webbrowser always opens new tab. I want to open in the same tab]
TitanSnow <tttnns1...@gmail.com> added the comment: Hi Cheryl, I think you may misunderstand. What it means is to open URL in the *same tab*, not *same window*, which is not described in documentation. Hi Tommy, It’s hard to say what is “the same tab”. Is it the current tab or the tab opened by last webbrowser.open call? If the user open a new tab in the opened browser, then which tab is “the same tab”? -- nosy: +tttnns ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32930> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue32917] ConfigParser writes a superfluous final blank line
Change by TitanSnow <tttnns1...@gmail.com>: Removed file: https://bugs.python.org/file47461/bpo-32917.patch ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32917> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue32917] ConfigParser writes a superfluous final blank line
Change by TitanSnow <tttnns1...@gmail.com>: -- pull_requests: +5621 stage: -> patch review ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32917> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12345] Add math.tau
Change by TitanSnow <tttnns1...@gmail.com>: -- pull_requests: +5622 ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue12345> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue32917] ConfigParser writes a superfluous final blank line
Change by TitanSnow <tttnns1...@gmail.com>: Removed file: https://bugs.python.org/file47460/final_blank_line.patch ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32917> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue32917] ConfigParser writes a superfluous final blank line
TitanSnow <tttnns1...@gmail.com> added the comment: Patch updated, included documentation and tests. -- Added file: https://bugs.python.org/file47461/bpo-32917.patch ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32917> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue32917] ConfigParser writes a superfluous final blank line
TitanSnow <tttnns1...@gmail.com> added the comment: **It's not final newline \n !** Maybe what I said confused. The "final blank line" does not mean the "final newline char". It means an extra blank line after last line. It might be clearer to represent it in a string:: '[section1]\nkey = value\n\n[section2]\nkey = value\n\n' It has *two* \n at end. I think it should be only one. -- ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32917> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue32917] ConfigParser writes a superfluous final blank line
New submission from TitanSnow <tttnns1...@gmail.com>: ``ConfigParser.write()`` writes a superfluous final blank line. Example:: import configparser cp = configparser.ConfigParser() cp['section1'] = {'key': 'value'} cp['section2'] = {'key': 'value'} with open('configparser.ini', 'w') as f: cp.write(f) The output file 'configparser.ini' will be:: (I added line number) 1 [section1] 2 key = value 3 4 [section2] 5 key = value 6 with a superfluous final blank line. Compare to ``GLib.KeyFile``:: import gi gi.require_version('GLib', '2.0') from gi.repository import GLib kf = GLib.KeyFile() kf.set_string('section1', 'key', 'value') kf.set_string('section2', 'key', 'value') kf.save_to_file('glib.ini') The output file 'glib.ini' will be:: (I added line number) 1 [section1] 2 key=value 3 4 [section2] 5 key=value without a superfluous final blank line. -- components: Library (Lib) files: final_blank_line.patch keywords: patch messages: 312608 nosy: tttnns priority: normal severity: normal status: open title: ConfigParser writes a superfluous final blank line type: behavior Added file: https://bugs.python.org/file47460/final_blank_line.patch ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32917> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com