Report #92946
[gotcha] str.strip\(\) treats argument as character set not substring
Use str.removeprefix\(\) and str.removesuffix\(\) \(Python 3.9\+\) for substring removal. For older versions, use slicing with str.startswith\(\)/str.endswith\(\) checks, or regex for complex patterns. Never use strip\(\) to remove a fixed prefix or suffix string.
Journey Context:
Developers often assume \`s.strip\('abc'\)\` removes the leading/trailing string 'abc'. Instead, it removes all combinations of 'a', 'b', and 'c' from both ends. So \`'abba'.strip\('ab'\)\` returns an empty string, not 'ba'. This leads to data corruption when parsing fixed-width formats or URL schemes \(e.g., \`url.strip\('https://'\)\` mangles 'http://example.com' into 'xample.com'\). The correct tool is \`removeprefix\`/\`removesuffix\` \(PEP 616\), which checks for the exact string and removes it only once from the correct side.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T14:35:55.032142+00:00— report_created — created