D-string vs str.dedent() - Ideas - Discussions on Python.org
Oct 11, 2023 ... d-string starts with triple quote ( """ or ''' ) followed by newline. The newline is not included in the string. · d-string ends with indent and ...
Oct 11, 2023 ... d-string starts with triple quote ( """ or ''' ) followed by newline. The newline is not included in the string. · d-string ends with indent and ...
Currently, Python lacks a path to explicitly declare structural typing without inheriting methods. This is a genuine gap in the affordances provided Python’s typing system, and without it, IMO, Python can’t fully cash out on structural typing.
Jul 28, 2023 · Fun thought. We have string concatenation, so what about the opposite? I was brainstorming how str -= x could work, and considering the purpose of .[l|r]strip(x) which would handle removing characters from any/either side, I think the syntax should equal the same as str.replace(x, ''), as there’s currently no shortcut for it. I would accept either the exact same, or kind of like strip(x ...
Jan 5, 2026 ... On dedenting and re-indenting replacement fields. Given this string: code = r""" def strip_each(lines): new_lines = [] for line in lines: ...
After several years of long discussion, I wrote up the d-string PEP. Old threads: Str.dedent vs str.removeindent D-string vs str.dedent() Markdown code-block style syntax for string lite…
Oct 23, 2024 · a) gh-119702: New dynamic algorithm selection for string search (+ `rfind` alignment) by dg-pb · Pull Request #120025 · python/cpython · GitHub b) Add tuple support to more str functions - #136 by dg-pb c) String API changes After these, implementing multi-pattern replace, split and similar will be straight forward.
Apr 2, 2019 ... …then the generator's caller's code ends up running in between the calls to __(a)enter__ and __(a)exit__ , and this corrupts the concurrency ...
so the sum with a string with a non-string will do an implicit cast to string of the non-string object and concatenate the two strings, as Java do. Furthermore, why limiting to infix operators?
Dec 1, 2019 · I would like str.replace, when given a set of characters, to replace occurrence of any of the characters in the set. I.e. 'ASDFGH'.replace(set('SFH'), '') == 'ADG' should then hold. It would mean I would not have to go to the trouble of using the re module for a common string operation. By extension, a set of multi-character strings should have any occurrences of the strings replaced, (in an ...
Source code: Lib/string.py String constants: The constants defined in this module are: Custom String Formatting: The built-in string class provides the ability to do complex variable substitutions ... Oh, and the colon marks the start of the format spec: [":" format_spec].
Oct 21, 2024 · Summary: I would like to propose an extension to the .replace() method to allow multiple substring replacements in a string using a dictionary. Currently, .replace() accepts only two arguments (the value to be replaced and the replacement value), which results in the need for multiple calls to replace different characters or words. With this new functionality, it would be possible to perform ...
This will not do what you want, because str(type_n) means the same string every time as you .replace each item. Unlike .append on a list, .replace on a string creates a new string and does not change the original string object (there are no methods for changing a string in-place).
Jul 20, 2022 · Split to two expressions for better readability. Note to the original code: You want to create a different number of strings. This cannot be done by using str.replace () because this function changes a string to a different string. This function cannot split or join strings which would be needed to change their number.
Jul 11, 2026 · But I’m not quite sure I understand the objective. If the input text is some HTML/JS block, can’t {/ { { appear in other contexts that you wouldn’t want to replace, such as inside a string? This reminds me of Jinja templates which I imagine is implemented as a custom parser.