I need to format a string with substrings of a variable. If I do:
sample="1234567890XXXX"
f"{sample[:5]}/{sample[5:10]}/{sample}/config"
It works fine:
'12345/67890/1234567890XXXX/config'
But if I use format:
"{sample[:5]}/{sample[5:10]}/{sample}/config".format(sample="1234567890XXXX")
I get an error:
TypeError: string indices must be integers, not 'str'
Any way to make it work with a format?
EDIT: just to clarify some things. The format string is passed through a command line argument and the format arguments automatically extracted from a pandas dataframe (as a dict). So, I do not thing the propsed solutions (f-strings and extra format arguments) will work.
args.out_path.format(**name)
format:"{s1}/{s2}/{sample}/config".format(sample="1234567890XXXX", s1={sample[:5]}, s2={sample[5:10]})