6 ms·
Every once in a while I search for something I need in Python and find that it only exists in Python 3, but I'm not quite convinced it's worth the effort to tra
by danra 8y ago
Every once in a while I search for something I need in Python and find that it only exists in Python 3, but I'm not quite convinced it's worth the effort to transition from 2.
However... I've just learned about Python 3's f-strings and they gave me a big smile, and probably the final push I needed :)
(Yes, I do know that sounds silly and there are probably much better reasons to transition to Python 3 ¯\_(ツ)_/¯ )
- btrettel 8y agoThanks for pointing f-strings out. I'm transitioning a script with a lot of string manipulation from Python 2 to 3 and this is better than concatenation, % formatting, or str.format().
- SatvikBeri 8y agof-strings really are great. As someone who has to do a lot of string manipulation, they're both easier to maintain and easier to read than any other Python alternative.
- pushingice 8y agoAt this point the best reason might be the 2020 deprecation. But yes, f-strings are great. Just did a small 2-3 migration last week, wasn't too bad.
- ahaferburg 8y agoThe non-Python-specific term is string interpolation, and it should be in every language. From a language design perspective, the problem is that the compiler needs to know about it, so it's a core feature, but for maximal efficiency it might require some feature that isn't part of a language's core, like string streams. Another possibility would be a powerful macro system that allows the transformation of a format string into code, but few languages offer that.