3 ms·
They just added a brand new feature in 3.8 that let's you just append = at the end for quick debugging: >>> f'{5+5=}' '5+5=10' >>> foo = 5 >>> f'{foo=}' 'f
by ehsankia 7y ago
They just added a brand new feature in 3.8 that let's you just append = at the end for quick debugging:
>>> f'{5+5=}'
'5+5=10'
>>> foo = 5
>>> f'{foo=}'
'foo=5'
https://docs.python.org/dev/whatsnew/3.8.html#f-strings-now-support-for-quick-and-easy-debugging https://docs.python.org/dev/whatsnew/3.8.html#f-strings-now-...
- gizmo385 7y agoThis just feels like another example of Python slowly creeping more esoteric syntax into the language, making it harder for beginners to approach the language.
- jplayer01 7y agoBeginners don't have to know or touch any of this though. They can keep using normal strings until at some point they learn about f strings and see a need for them. You don't need to stop adding features to a language just because a beginner won't be able to learn everything. They don't need to.
- simonh 7y agoI think the point is, a beginner coming across some code using such esoteric features is going to be a bit lost as to what's going on. With most of Python you can see what it's doing even if you didn't know the syntax before. That's true of basic f-strings, but not so much with some of this stuff.
- makapuf 7y agoYeah languages are meant to be read even by beginners. I think a language like python shines by being small (in design) yet powerful (by capability). Having myriads of "nice for one use case" feature in the language is not the way forward. I long for the time where % format and .format are removed from the language spec. Even if they still work on the implementation for compatibility. Please remove things.
- batisteo 7y ago> Please remove things. We're not done with Python 2 yet. This would be a Python 4 for sure. That's not according the philosophy of backward compatibility of Python (even if I agree with you).
- makapuf 7y agoYes backward compatibility is not an option (lets avoid redoing python3 trauma ) and simply delegating coexistence of old and new features to implementation is a bit lazy. However documenting one way as the current one and other features as old ways, for backward compatibility can simplify things.
- jacobush 7y agoI don't get it. Why not just write: >>> f'{foo}=' 'foo=5'
- baq 7y agothere's a pattern in debugging that basically looks like print('foo=',foo) like all languages should, if a pattern is wide-spread, useful and basically boilerplate, python decided to create a language shortcut for it. print('f{foo=}')
- stOneskull 7y agof before the quote though
- baq 7y agodoh! classic 'your bick is dig', can't even edit now :(
- istjohn 7y agoAs someone who probably relies on print statements too much for debugging, I love this.