[Python-ideas] Briefer string format

Mike Miller python-ideas at mgmiller.net
Mon Jul 20 06:42:11 CEST 2015


Thanks for thinking about it, Chris.  After several mentions of u'' and b'' I 
was waiting patiently for '' and r''.  I guess r'' does nothing but what does '' 
or "" do at runtime?

     "\tcommand line --params\n"  -->  "	command line --params
"

It looks like there is some runtime conversion happening there, though I don't 
know the implementation details.

On Mon, 20 Jul 2015 10:51:28 +1000, Chris Angelico wrote:
> Will an f"..." format string be mergeable with other strings? All the
> other types of literal can be (apart, of course, from mixing bytes and
> unicode), but this would have to be something somehow different. In
> every way that I can think of, this is not a literal - it is a
> construct that results in a run-time operation. A context-dependent
> operation, at that. That's why I'm -1 on this looking like a literal.
> ChrisA

Also, Re: below, this a subtle but important improvement Steve, thanks!
Yes, a transformation from:

     f"{x} {y}"
to
     "string with braces".format(x=x, y=y)

This is very much what I was thinking.  If the second form is ok, the first 
should be too, syntax aside, if it does the same thing.  The drawback being it 
might take a tool like an upgraded pyflakes/pycharm to notice y hadn't been 
defined yet.

(Might a further optimization in C be possible to skip the function call, but
basically work like this?  No locals/globals()?)

-Mike

On Mon, Jul 20, 2015 at 10:43 AM, Steve Dower <Steve.Dower at microsoft.com> wrote:
 > Why wouldn't this be a compile time transform from f"string with braces"
 > into "string with braces".format(x=x, y=y, ...) where x, y, etc are...


More information about the Python-ideas mailing list