
On 08/08/2015 09:49 AM, Stefan Behnel wrote:
Mike Miller schrieb am 20.07.2015 um 01:35:
csstext += '{nl}{key}{space}{{{nl}'.format(**locals())
This looks a bit better if you ignore the right half, but it is longer and not
csstext += '{nl}{key}{space}{{{nl}'.format(nl=nl, key=key, ... # uggh csstext += '{}{}{}{{{}'.format(nl, key, space, nl)
Is this an actual use case that people *commonly* run into? I understand that the implicit name lookups here are safe and all that, but I cannot recall ever actually using locals() for string formatting.
There are several ways to accomplish that line. If you look below it there two alternatives, that are suboptimal as well.
The above looks magical to me. It's completely unclear that string ... I'd prefer not seeing a "cool feature" added just "because it's cool". If it additionally is magic, it's usually not a good idea.
Direct string interpolation is a widely desired feature, something the neckbeards of old, hipsters, and now suits have all agreed on. Since Python uses both " and ' for strings, there isn't an obvious way to separate normal strings from interpolated ones like shell languages do. That leaves, 1. interpolating all strings, or instead 2. marking those we want interpolated. Marking them appears to be the more popular solution here, the last detail is whether it should be f'', i'', or $'', etc. Letters are easier to read perhaps. The implementation is straightforward also. Since the feature will take about 30 seconds to learn, and pay back with a billion keystrokes saved, I'd argue it's a good tradeoff. -Mike