6 ms·
TIL python has a webbrowser module
by tersers 5y ago
TIL python has a webbrowser module
- hansor 5y agoMe too... Hilarious!
- codetrotter 5y agoAnd it's even using the user preferred browser! 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.
- zirak 5y agoFrom the python source code: https://github.com/python/cpython/blob/11749e2dc20ad6a76e9a39e948853e89b2b4bbed/Lib/webbrowser.py#L619 https://github.com/python/cpython/blob/11749e2dc20ad6a76e9a3... It seems to be shelling out to osascript, either telling it to OpenURL or open.
- mxuribe 5y agoI just learned this myself the other day... 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/ https://automatetheboringstuff.com/2e/chapter12/ I have not played much with it yet, but man, python continues to impress me!
- vascocosta 5y agoMe too and I'm a long time Python programmer.
- jp_sc 5y agoBut not a texteditor. You can use this library for that: https://pypi.org/project/texteditor/ https://pypi.org/project/texteditor/ (Disclaimer: I’m the author)
- diogenesjunior 5y agoThere's not really a reason for a built in text editor
- jp_sc 5y agoIs not a built in text editor, is a command to open programmatically your default text editor to edit a file (new or existing). 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.
- deleted 5y ago[deleted]
- BiteCode_dev 5y agoIdle
- ehsankia 5y agoYou missed the point of what the library does. Similar to webbrowser (which isn't a full browser), all it does is open your default text editor.
- boublepop 5y agoBack in the day, python was popular because it was a “batteries included” language, which meant I supposedly had almost everything you would need right there in the standard language. These days of cause no one runs python without going on a shopping spree of additional packages on pypi, so it would be less of a big deal if it didn’t include a browser lib, or a GUI lib out of the box.