我想根据我的要求替换某些非硬编码的字符串,如inputFile,outputFile和outputFileSize 例如
COMMAND = """Application.exe inputFile=./Input.txt
outputFile="Output/Output.txt" outputFileSize=20Kb"""
我想做
inputfilename =' ./ File1.txt'
outputfilename ='输出/ File2.txt'
outputfilesize =' 90Kb'
这样我替换的字符串应该像这样
COMMAND = """Application.exe inputFile=./File1.txt
outputFile="Output/File2.txt" outputFileSize=90Kb"""
这样做的正确方法是什么?
答案 0 :(得分:0)
可能的解决方案:
command = """Application.exe inputFile=./Input.txt
outputFile="Output/Output.txt" outputFileSize=20Kb"""
inputfilename = './File1.txt'
outputfilename = 'Output/File2.txt'
outputfilesize = '90Kb'
command = command.replace("./Input.txt", inputfilename)
command = command.replace("Output/Output.txt", outputfilename)
command = command.replace("20Kb", outputfilesize)
print command
输出:
Application.exe inputFile=./File1.txt
outputFile="Output/File2.txt" outputFileSize=90Kb
提示:
string.replace
方法的详细信息,请查看the documentation。