5 ms·
I've put together a proposal to have all strings be f-strings by default. Then you could drop the "f" prefix. I also propose adding a "p" prefix (for "plain")
by ericvsmith 6y ago
I've put together a proposal to have all strings be f-strings by default.
Then you could drop the "f" prefix. I also propose adding a "p" prefix (for "plain") to remove the f-string parsing behavior.
I talked about it at the last Python core sprint, and it only got lukewarm support, so I'm not sure I'm going to pursue it.
- cdrini 6y agoI would personally be quite against that. That's a pretty large breaking change, with no clear benefit. It doesn't make the feature more discoverable, since you still need to know that using "{}" will cause interpolation. I'd say net zero effect on readability; mostly just individual preference. And potential negative impact on performance.
- ericvsmith 6y agoThere would be a __future__ import to turn it on, at least for some number of releases. But yeah, I'm not sure it should ever be the default behavior. It makes most sense to me as a per-module opt-in, but then a __future__ import doesn't make sense. And we've resisted having per-module pragmas, so maybe it's dead in the water.
- boothby 6y ago> And we've resisted having per-module pragmas, so maybe it's dead in the water. There's a hack for that (no apologies for the self promotion; the project is a just funnin') https://github.com/boothby/dissert https://github.com/boothby/dissert
- Blikkentrekker 6y agoCertainly this will lead to rather confused programmers. F-strings certainly seem like opt-in behavior to me.
- dragonwriter 6y ago> I've put together a proposal to have all strings be f-strings by default. Please, no. I mean, it would be a breaking change, which needs a really compelling case, will make all introductory material wrong, and...offers what benefit?
- earthboundkid 6y agoI think that would be a pretty serious harm to Python as a language. When I was learning Python, I was using PHP, which has $ interpolation for double quoted strings but not single quotes. I didn’t understand how PHP worked at all and it really confused me. In retrospect, I don’t know why it was so hard to wrap my head around, but it was. Learning Python was liberating because I knew exactly when and how interpolation would take place. The decision not to follow the lead of Perl and Bash and auto-interpolate was made deliberately by Guido many years ago. It would be a shame to go back on that decision now.
- roelschroeven 6y ago> I've put together a proposal to have all strings be f-strings by default. Please don't do that. Seriously. There is this trend in the Python community of blurring the line between a plain string and a formatting operation on that string, but there is a fundamental difference between the two. Instead of trying to ignore that difference, the language should make the difference explicit. "Explicit is better than implicit" is one of the things I like so much about Python. Please don't throw that away. There is and should be a clear and fundamental difference between a plain string and a string formatting operation. The plain string is clearly the more fundamental of the two, so it should be the default. And then there's the whole issue of breaking code with such a change. Again, please don't do it. Don't change the language in such a fundamental way.
- GlitchMr 6y agoWon't happen. This would be a breaking change that would break pretty much every usage of `str.format`. Releasing a new incompatible version of a language is unlikely considering Python 2 to Python 3 migration mess.
- deleted 6y ago[deleted]