I can receive 2 types of strings from the user.
cmd1 = inst1.exe license.dat
cmd2 = {{installer}} {{license}}
And I have to replace the strings between braces with something from a dictionary ({'installer': 'inst1.exe', 'license': 'license.dat'}
)
I'm trying something like that:
def my_replace_method(cmd, dict)
for key, value in dictionary.items():
cmd.replace(key, value)
for call:
my_replace_method(cmd2, dict)
The output I got was: "{{inst1.exe}} {{license.dat}}"
instead of "inst1.exe license.dat"
and
my_replace_method(cmd1, dict)
The output I got is "inst1.exe license.dat.dat"
instead of "inst1.exe license.dat"
My expected output for both commands is:
inst1.exe license.dat
How can I write a method that works for both types of input?
question from:
https://stackoverflow.com/questions/65904276/replace-words-between-double-brackets-in-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…