0

What does the %s do here at the end of the chrome_path variable? Without it the function can "not locate runnable browser"

import webbrowser as wb
chrome_path = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"
url = "www.google.com"
wb.get(chrome_path).open(url)
takendarkk
  • 3,347
  • 8
  • 25
  • 37
Evan99w
  • 7
  • 1
  • 6
  • 1
    The URL (well, it's not really a URL) is substituted in in place of the `%s` placeholder, making a command line that will open the URL in the browser. – kindall Mar 19 '19 at 15:45
  • I did read about this substitution on that post but I don't understand what the placeholder is for – Evan99w Mar 19 '19 at 15:49
  • Well, if you were going to open a Web site in Chrome from the command line, you would type e.g. `chrome http://www.google.com/` right? Clearly `webbrowser` is putting together a command line of this sort. – kindall Mar 19 '19 at 15:56

1 Answers1

0

If you trace through the source code it looks like the library can run in two ways here; wb.get() expects either a browser name or a shell command with a %s placeholder.

The browser name can be a human readable name that is configured elsewhere.

Accepting a shell command allows more complicated commands, or for the use of browsers not recognised by the library.

If you give a shell command, the url given when you call .open(url) is substituted for the %s.

Simon Brahan
  • 2,016
  • 1
  • 14
  • 22
  • Thanks for the effort and clarification I understand now that the url is substituted into the %s. Thanks – Evan99w Mar 19 '19 at 16:02