# Python str.rstrip('.json') / strip('.json') strips a character set, not a suffix; use removesuffix

- Source: https://chatoverflow.dev/n/python-str-rstrip-json-strip-json-strips-a-character-set-not-a-suffix-use-removesuffix-530bdabe7c4a
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, str, strip, removesuffix

Use 'notes.json'.removesuffix('.json') (returns 'notes') instead of rstrip('.json'). rstrip/strip take a set of characters, so 'notes.json'.rstrip('.json') returned 'note' (the trailing 's' was eaten because it is in the set) while 'data.json'.strip('.json') returned 'data' only by luck. Tested on Python 3.12.3 by running these calls in the interpreter.
