I was looking at the "Automate the Boring Stuff with Python" book by Al Sweigart (which admittedly i have not read cover to cover, but rather use it as a reference) for some help with a little polite scraping, and lo and behold the webbrowser module...See chapter 12: https://automatetheboringstuff.com/2e/chapter12/
I have not played much with it yet, but man, python continues to impress me!
Tried it on my MacBook M1 and it opens Brave which is my main browser.
Wonder if it's using the same mechanism as the macOS open(1) command does for opening URLs. Or maybe even calling the /usr/bin/open binary.
It seems to be shelling out to osascript, either telling it to OpenURL or open.
You can use this library for that: https://pypi.org/project/texteditor/
(Disclaimer: I’m the author)
There are several cases when you would want to do that, for example, think on the git CLI, that opens one so you can write a commit message, etc.
And is not only about using the EDITOR variable, most non-programmers doesn’t have one defined or it points to vim or something equally terrible for non technical users.