title: How do I convert a string into an f-string?
body: <p>I was reading <a href="https://cito.github.io/blog/f-strings/" rel="nofollow noreferrer">this blog post</a> on Python's new <a href="https://peps.python.org/pep-0498/#how-to-denote-f-strings" rel="nofollow noreferrer">f-strings</a> and they seem really neat.  However, I want to be able to load an f-string from a string or file.</p>
  <p>I can't seem to find any string method or other function that does this.</p>
  <p>From the example in the blog post:</p>
  <pre><code>name = 'Fred'
  age = 42
  f&quot;My name is {name} and I am {age} years old&quot;
  
  'My name is Fred and I am 42 years old'
  </code></pre>
  <p>But what if I had a string <code>s</code>?  I want to be able to <a href="https://peps.python.org/pep-0498/#how-to-denote-f-strings" rel="nofollow noreferrer">eff-ify</a> <code>s</code>, something like this:</p>
  <pre><code>name = 'Fred'
  age = 42
  s = &quot;My name is {name} and I am {age} years old&quot;
  effify(s)
  </code></pre>
  <hr />
  <p>It turns out I can already perform something similar to <code>str.format</code> and garner the performance pick up.  Namely:</p>
  <pre><code>format = lambda name, age: f&quot;My name is {name} and I am {age} years old&quot;
  format('Ted', 12)
  
  'My name is Ted and I am 12 years old'
  </code></pre>