I want to do an output name for a file and the input will/should be like this:

"seriesName Episode epNr 720p"

and I want to turn the seriesName and the epNr to variables I set. For example:

seriesName="Mr. Robot"

and if I do print(output), the output should be

"Mr. Robot Episode 10 720p"

2 Answers

ehudt On Best Solutions

Try using str.replace:

myString = "seriesName Episode epNr 720p"
replacedString = myString.replace('seriesName', 'Mr. Robot').replace('epNr', '10')

Or better yet, use str.format with keyword arguments:

In [1]: myString = "{seriesName} Episode {epNr} 720p"    
In [2]: myString.format(seriesName='Mr. Robot', epNr='10')
Out[3]: 'Mr. Robot Episode 10 720p'
Rahil Hastu On

A more general way of achieving the same:

seriesName="Mr. Robot"

print "{} Episode {} 720p".format(seriesName,epNr)