title: How can I print a string using .format(), and print literal curly brackets around my replaced string
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5466451/how-can-i-print-a-literal-characters-in-python-string-and-also-use-format">How can I print a literal &ldquo;{}&rdquo; characters in python string and also use .format on it?</a>  </p>
  </blockquote>
  
  
  
  <p>Basically, I want to use .format(), like this:</p>
  
  <pre><code>my_string = '{{0}:{1}}'.format('hello', 'bonjour')
  </code></pre>
  
  <p>And have it match:</p>
  
  <pre><code>my_string = '{hello:bonjour}' #this is a string with literal curly brackets
  </code></pre>
  
  <p>However, the first piece of code gives me an error. </p>
  
  <p>The curly brackets are important, because I'm using Python to communicate with a piece of software via text-based commands. I have no control over what kind of formatting the fosoftware expects, so it's crucial that I sort out all the formatting on my end. It uses curly brackets around strings to ensure that spaces in the strings are interpreted as single strings, rather than multiple arguments — much like you normally do with quotation marks in file paths, for example.</p>
  
  <p>I'm currently using the older method:</p>
  
  <pre><code>my_string = '{%s:%s}' % ('hello', 'bonjour')
  </code></pre>
  
  <p>Which certainly works, but .format() seems easier to read, and when I'm sending commands with five or more variables all in one string, then readability becomes a significant issue.</p>
  
  <p>Thanks!</p>