[Python-ideas] Outside the box string formatting idea
Ron Adam
ron3200 at gmail.com
Mon Aug 10 01:08:54 CEST 2015
On 08/09/2015 06:14 PM, Mike Miller wrote:
> My take:
>
> On 08/09/2015 02:20 PM, Ron Adam wrote:
>> It may be possible to do that in this case as an actual expression rather
>> than
>> as a string and still get most of the benefits. Shorter more compressed
>> isn't
>> always better when it comes to readability.
>
> Really the idea here is brevity. The long-form versions are still
> available if they would be better in a particular instance.
>
> > (% 'result =' foo())
>
> I found these interesting, reminds me of polish notation. However these
> would need enhancements to syntax as it would be currently invalid. f''
> is likely easier to implement w/o syntax changes. Also, it doesn't look
> much like python.
There are actually too parts...
(% ...) Handles implicit concatination and string conversion.
And {expr format} handles the formatting, inside (% ...) context only.
So these only work in string format expressions, just like special syntax
for comprehensions only works in comprehensions.
As I suggested, I think it's the closest you can get and still not put the
expressions into the strings.
Comma's could be used to separate things, but it's not that much of a
stretch to go from ....
'a' 'b' --> 'ab'
to
a = 'a'
b = 'b'
(% a b) --> 'ab'
But we could have...
(% a, b) If that seems more pythonic.
Cheers,
Ron
More information about the Python-ideas
mailing list