News for hackers. Stuff that matters.
Re:Python f-strings are the best syntax sugar i never knew a... by tedmiston on Tuesday January 23, 2018 @07:24PM (#16219236)
You can do cool nested calls with them too.

    >>> class A:
    ...     def __init__(self):
    ...         self.foo = 5
    ...     def bar(self):
    ...         return 'cake'
    ...
    >>> a = A()
    >>> f'{a.foo}'
    '5'
    >>> f'{a.bar()}'
    'cake'

    >>> x = {'b': 1, 'c': 2}
    >>> f"{x['b']}"
    '1'
Re:Python f-strings are the best syntax sugar i never knew a... by tudelo on Wednesday January 24, 2018 @09:53AM (#16223096)
Interesting. Thanks for the post. I always just concatenated them out of laziness, and this looks even lazier.
Re:Python f-strings are the best syntax sugar i never knew a... by odonnellryan on Wednesday January 24, 2018 @12:23PM (#16224413)
It's super nice when you're working on reporting software: software that needs to quickly shoot out a string like this from time-to-time!

It's much nicer to write this:

f"{account_name} {pretty_date(start_date)} - {pretty_date(end_date)} account attribution"

and MUCH easier to maintain than the alternative...!

Re:Python f-strings are the best syntax sugar i never knew a... by pyedpiper on Wednesday January 24, 2018 @01:22PM (#16224960)
saw this after posting, so epicly useful. Alreadying thinking of some nice concise, explanatory custom Exception descriptions..