<div dir="ltr">Automatically injecting from the locals or globals is a nice source of bugs. Explicit is better than implicit, especially in case where it can lead to security bugs.<div><br></div><div>-1</div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><font face="arial, helvetica, sans-serif">--- Bruce<br></font><div><div><font face="arial, helvetica, sans-serif">Check out my new puzzle book: <a href="http://J.mp/ingToConclusions" target="_blank">http://J.mp/ingToConclusions</a></font><br></div></div><div><font face="arial, helvetica, sans-serif">Get it free here: <a href="http://J.mp/ingToConclusionsFree" target="_blank">http://J.mp/ingToConclusionsFree</a> (available on iOS)</font></div><div><br></div><div><br></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
<br><div class="gmail_quote">On Sun, Jul 19, 2015 at 4:35 PM, Mike Miller <span dir="ltr"><<a href="mailto:python-ideas@mgmiller.net" target="_blank">python-ideas@mgmiller.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
Ok, I kept the message brief because I thought this subject had previously been discussed often.  I've expanded it to explain better for those that are interested.<br>
<br>
---<br>
<br>
Needed to whip-up some css strings, took a look at the formatting I had done<br>
and thought it was pretty ugly.  I started with the printf style, and had<br>
pulled out the whitespace as vars in order to have a minification option:<br>
<br>
    csstext += '%s%s%s{%s' % (nl, key, space, nl)<br>
<br>
Decent but not great, a bit hard on the eyes.  So I decided to try .format():<br>
<br>
    csstext += '{nl}{key}{space}{{{nl}'.format(**locals())<br>
<br>
This looks a bit better if you ignore the right half, but it is longer and not<br>
as simple as one might hope.  It is much longer still if you type out the<br>
variables needed as kewword params!  The '{}' option is not much improvement<br>
either.<br>
<br>
   csstext += '{nl}{key}{space}{{{nl}'.format(nl=nl, key=key, ...  # uggh<br>
   csstext += '{}{}{}{{{}'.format(nl, key, space, nl)<br>
<br>
I've long wished python could format strings easily like bash or perl do, ...<span class=""><br>
and then it hit me:<br>
<br></span>
    csstext += f'{nl}{key}{space}{{{nl}'<br>
<br>
An "f-formatted" string could automatically format with the locals dict. Not<br>
yet sure about globals, and unicode only suggested for now.  Perhaps could be<br>
done directly to avoid the .format() function call, which adds some overhead<br>
and tends to double the length of the line?<br>
<br>
I remember a GvR talk a few years ago giving a 'meh' on .format() and have<br>
agreed, using it only when I have a very large or complicated string-building<br>
need, at the point where it begins to overlap Jinja territory.  Perhaps this is<br>
one way to make it more comfortable for everyday usage.<span class=""><br>
<br>
I've seen others make similar suggestions, but to my knowledge they didn't<br>
include this pleasing brevity aspect.<br>
<br></span>
-Mike<br>
<br>
<br>
<br>
On 07/19/2015 04:27 PM, Eric V. Smith wrote:<span class=""><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Jul 19, 2015, at 7:12 PM, Mike Miller <<a href="mailto:python-ideas@mgmiller.net" target="_blank">python-ideas@mgmiller.net</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Have long wished python could format strings easily like bash or perl do, ...<br>
and then it hit me:<br>
<br>
    csstext += f'{nl}{selector}{space}{{{nl}'<br>
<br>
(This script included whitespace vars to provide a minification option.)<br>
<br>
I've seen others make similar suggestions, but to my knowledge they didn't<br>
include this pleasing brevity aspect.<br>
</blockquote>
<br>
What would this do? It's not clear from your description.<br>
<br>
Eric.<br>
<br>
<br>
</blockquote>
_______________________________________________<br>
Python-ideas mailing list<br>
</span><a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div><br></div>