I have an issue where I need to format a string using python2.7. The method I wanted use works fine using f strings in 3.6, but those don't work natively in 2.7. The string contains some already existing pattern matching that seems to cause format to not want to work. See a simple example.
>>> h = '{device} "\\b\d{9,12}\\b" {count1} {count2}'
>>> h.format(device='CISCO1', count1=1, count2=2)
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
h.format(device='CISCO1', count1=1, count2=2)
KeyError: '9,12'
I have removed the full string as it is proprietary but this captures the problem. I need to be able to format the device, count1, and count2
without needing the {9,12}
to be considered. I tried using the % operator but that too caused problems. Is there an easy way to do this?