Lets say I have this line:
"My name is {name}".format(name="qwerty")
I know that the variable name is name
and so I can fill it.
But what if the word inside the {}
always changes, like this:
"My name is {name}"
"My name is {n}"
"My name is {myname}"
I want to be able to do this:
"My name is {*}".format(*=get_value(*))
Where *
is what ever word was given inside the {}
Hope I was clear.
EDIT:
def get_value(var):
return mydict.get(var)
def printme(str):
print str.format(var1=get_value(var1), var2=get_value(var2))
printme("my name is {name} {lastname}")
printme("your {gender} is a {sex}")
Having this, I can't hard code any of the variables inside printme
function.