[Python-ideas] Briefer string format

Ben Finney ben+python at benfinney.id.au
Sat Jul 25 09:55:18 CEST 2015


Guido van Rossum <guido at python.org> writes:

> On Fri, Jul 24, 2015 at 10:27 PM, Ben Finney wrote:
>
> > > Steven D'Aprano wrote:
> > > > I don't think I want this behaviour:
> > > >
> > > >     f'{spam}' '{eggs}'
> > > >     => format(spam) + '{eggs}'
> […]
> >
> >     >>> 'foo\abar' r'lorem\tipsum' 'wibble\bwobble'
> >     'foo\x07barlorem\\tipsumwibble\x08wobble'
> >
> >     >>> type(b'abc' 'def' b'ghi')
> >       File "<stdin>", line 1
> >     SyntaxError: cannot mix bytes and nonbytes literals
> >
> > […]
> > Is the proposed ‘f’ prefix, on a fragment in implicit concatenation,
> > meant to have behaviour analogous to the ‘r’ prefix or the ‘b’
> > prefix, or something else? What's the argument in favour of that
> > choice?
>
> It *must* work like r'' does. Implicit concatenation must be thought
> of as letting each string do its thing and then concatenating using
> '+', just optimized if possible. The error for b'' comes out because
> the '+' refuses b'' + ''.

That makes sense, and is nicely consistent (‘f’, ‘r’, and ‘b’ all apply
only to the one fragment, and then concatenation rules apply). Thanks.

> I find it a sign of the times that even this simple argument goes on
> and on forever. Please stop the thread until Eric has had the time to
> write up a PEP.

I found this discussion helpful in knowing the intent, and what people's
existing expectations are.

Hopefully you found it helpful too, Eric! In either case, I look forward
to your PEP.

-- 
 \       “… one of the main causes of the fall of the Roman Empire was |
  `\        that, lacking zero, they had no way to indicate successful |
_o__)                  termination of their C programs.” —Robert Firth |
Ben Finney



More information about the Python-ideas mailing list