python - How to mix named and unnamed string formatting -


how mix named , unnamed string formatting? consider following not-running example:

s = "{:s}_{later}_{:s}".format("foo", "bar") s1 = s.format(later="later") 

i want first format somthing including named postioner later formatting. how archieve in python?

you'll have escape named formatting part:

>>> "{:s}_{{later}}_{:s}".format("foo", "bar") 'foo_{later}_bar' >>> _.format(later="later") 'foo_later_bar' 

or other way around:

>>> "{{:s}}_{later}_{{:s}}".format(later="later") '{:s}_later_{:s}' >>> _.format("foo", "bar") 'foo_later_bar' 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -