1

I'm trying to name an output file by adding the string "resampled" to the input file name

outputfile = '%s.tif' % '{0}+ {1}'.format(inputfile, '_resampled') 

How can I do this so my output file is saved as inputfile_resampled.tif?

For example:

NIR would become NIR_resampled.tif.

4
  • Why the complicated-double string formatting? Why not just "{}.tif".format(inputfile+ '_resampled')? Commented Oct 4, 2020 at 12:04
  • Does this answer your question? How to add an id to filename before extension? ; or stackoverflow.com/questions/24409984/… Commented Oct 4, 2020 at 12:06
  • ``` "{}.tif".format(inputfile+ '_resampled')``` didn't work! Commented Oct 4, 2020 at 12:18
  • Check out the links above. That should give you your answer. The above suggestion will not work if inputfile is a full path and not just the file's name... Commented Oct 4, 2020 at 12:20

1 Answer 1

1

Using f-string

outputfile = f"{inputfile}_resampled.tif"

Using standard string

outputfile = "{}_resampled.tif".format(inputfile)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.