@rebeccasaurus I know that if I want to fiddle about with paths and filenames in Python, I use the os.path module. I suspect that something like this might help? https://docs.python.org/3/library/os.path.html#os.path.splitext
I couldn't tell you about the internals of how it works or the details how the str.split menthod is implemented. The bulk of what I do with Python the long bit is the database anyway so I don't tend to keep close track of it.