I’m trying to do this:
commands = { ‘py’: ‘python %s’, ‘md’: ‘markdown "%s" > "%s.html"; gnome-open "%s.html"’, }
commands[‘md’] % ‘file.md’
But like you see, the commmands[‘md’] uses the parameter 3 times, but the commands[‘py’] just use once. How can I repeat the parameter without changing the last line (so, just passing the parameter one time?)
Note: The accepted answer, while it does work for both older and newer versions of Python, is discouraged in newer versions of Python.
For this reason if you’re using Python 2.6 or newer you should use
str.formatinstead of the old%operator: