<instructions>Your goal is to analyze the following comment and estimate how highly it will be upvoted by the Hacker News community.</instructions><comment><author>reidrac</author><text>You can also:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    a = 4
    &amp;#x27;A is: %(a)d&amp;#x27; % locals()
&lt;/code&gt;&lt;/pre&gt;
Perhaps is my experience programming in C, but &amp;quot;format&amp;quot; looks lees familiar and I tend to use the old style formatting.</text><parent_chain><item><author>fragmede</author><text>They missed my favorite trick!
locals() will give you a dict of, well, local variables, which generally coincides with what you want, so:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    a = 4
    &amp;#x27;A is: {a}&amp;#x27;.format(**locals())
&lt;/code&gt;&lt;/pre&gt;
works as expected.</text></item></parent_chain></comment><story><title>PyFormat – Practical examples of old and new style string formatting</title><url>http://pyformat.info</url><text></text></story>
<instructions>Your goal is to analyze the following comment and estimate how highly it will be upvoted by the Hacker News community.</instructions><comment><author>pfranz</author><text>I&amp;#x27;ve seen this and tried to avoid it since getting bitten my moving code around and not catching which variables were used.  It might have been even more obscured with something like TEMPLATED_STRING.format(&lt;i&gt;&lt;/i&gt;locals())</text><parent_chain><item><author>fragmede</author><text>They missed my favorite trick!
locals() will give you a dict of, well, local variables, which generally coincides with what you want, so:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    a = 4
    &amp;#x27;A is: {a}&amp;#x27;.format(**locals())
&lt;/code&gt;&lt;/pre&gt;
works as expected.</text></item></parent_chain></comment><story><title>PyFormat – Practical examples of old and new style string formatting</title><url>http://pyformat.info</url><text></text></story>