Default substituting %s in python scripts

prahallada picture prahallada · May 10, 2011 · Viewed 92.8k times · Source

Sometimes in Python scripts I see lines like:

cmd = "%s/%s_tb -cm cond+line+fsm -ucli -do \"%s\""

Where is the %s in the above line substituted? Does Python have some stack of strings and it pops them and replaces %s?

Answer

John Gaines Jr. picture John Gaines Jr. · May 10, 2011

That would be later used in something like:

print cmd % ('foo','boo','bar')

What you're seeing is just a string assignment with fields in it which will later be filled in.