Search code examples
string-formattingconfiguration-files

What is the use of Percent-S (%s) at the end of strings? (Not string formatting)


I'm trying to configure the browser for Jupyter Notebook, and in the .jupyter config file, I am confused by this line.

What is the point of %s at the end of the string?

c.NotebookApp.browser = u'open -a chrome.exe %s'

When I search for %s in strings on the internet, I get the pages related to string formatting (where the string is followed by an additional % variable, to substitute the variable into the string). This is totally unrelated isn't it?


Solution

  • The string is likely passed to sprintf(), which inserts a string parameter in place of %s. See man printf.

    In this case, the URL in inserted as a parameter for the open command.

    The author of the config file format decided to use string formatting here, so you can insert the URL parameter anywhere in the string, and not only at the end of it, i.e.:

    c.NotebookApp.browser = u'/usr/bin/my_browser -new -url %s -some -more -parameters'
    

    Then at runtime of the application, the URL parameter is injected with string formatting:

    shellCmd = config.NotebookApp.browser % targetUrl
    

    It is important. Don't delete it.