PCM
PCM

Reputation: 3011

How to "open with" in python using webbrowser

I wanted to know if there was a way to open files using web browser module in python, but other than the default program.

So when we right-click a file, there is an option called open with > right? So, how can I use web browser to open with other programs.

import webbrowser
webbrowser.open_new(path of file)

When I use the above, it opens the file with the default program. So for example, if I use this to open a .txt file, it will open it in notepad as it is the default. How do I make it so that it opens with other applications like - Word or something.

Thanks for any help or suggestion!

Upvotes: 1

Views: 740

Answers (1)

Everton P M A
Everton P M A

Reputation: 197

Look this page - https://docs.python.org/3/library/webbrowser.html

controller.open(url, new=0, autoraise=True) Display url using the browser handled by this controller. If new is 1, a new browser window is opened if possible. If new is 2, a new browser page (“tab”) is opened if possible.

Upvotes: 0

Related Questions