Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

TIL python has a webbrowser module


Back 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.


I 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/

I have not played much with it yet, but man, python continues to impress me!


And 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.


From the python source code: https://github.com/python/cpython/blob/11749e2dc20ad6a76e9a3...

It seems to be shelling out to osascript, either telling it to OpenURL or open.


Me too and I'm a long time Python programmer.


Me too... Hilarious!


But not a texteditor.

You can use this library for that: https://pypi.org/project/texteditor/

(Disclaimer: I’m the author)


There's not really a reason for a built in text editor


Is 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.


Idle


You 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: