Search code examples
pythonpython-webbrowser

Python: What does %s do here?


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)

Solution

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