I am trying to format a string to pass to os.popen()
so I can do some parsing in awk
. I'm using python 2.7.10. When I try to format the string, python appears to think that I'm trying to assign a new key/value pair to a dictionary.
>>> path="xyz"
>>> string="awk {}".format(path) #<--- This works as expected!
>>> string
'awk xyz'
>>>
>>> string="awk 'BEGIN{FS=\"\t\"}{print $1}' {}" #<--- This works, but not what I want
>>> string
'awk \'BEGIN{FS="\t"}{print $1}\' {}'
>>>
>>> string="awk 'BEGIN{FS=\"\t\"}{print $1}' {}".format(path) #<--- This fails b/c Python thinks I'm trying to do something with dictionaries?
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'FS="\t"'
How do I format my string
in the case where there are {}
that are not intended to get formatted and ones that are?