I would like to add some characters to the text output.
Here is my code:
thumbnailname = detail.xpath('.//h1/text()').get().replace(' ','-')
Here is my text output:
Apple-iPhone-13-Pro-Max
How do I get the following output?
My-Apple-iPhone-13-Pro-Max.jpg
CodePudding user response:
Just concatenate the strings:
thumbnailname = "My-" detail.xpath('.//h1/text()').get().replace(' ','-') ".jpg"
CodePudding user response:
you have 2 easy ways to add strings before and after your string:
yourstring = "start{0}end".format(yourstring)yourstring = "start" yourstring "end"
in your case:
thumbnailname = detail.xpath('.//h1/text()').get().replace(' ','-')
thumbnailname = "My-" thumbnailname ".jpg"
or
thumbnailname = "My-{0}.jpg".format(detail.xpath('.//h1/text()').get().replace(' ','-'))"
