Suppose I have this line:
"My name is {name}".format(name="qwerty")
I know that the name of the variable is name , and so I can fill it out. But what if the word inside {} always changes, for example:
"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 was ever entered in {}
I hope that I understand.
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}")
However, I cannot hardcode any of the variables inside the printme function.
python
MichaelR
source share