News for hackers. Stuff that matters.
Re:What's Coming in Python 3.8 by bpchaps on Wednesday July 17, 2019 @09:23PM (#20465775)
Here's a clean way to do that:

  str_fmt = "File exists, not uploading: {filename} -> {bucket}, {key}"
  fmt_vals = dict(filename=filename, bucket=bucket, key=key)
  raise ValueError(str_fmt.dedent().format(**fmt_vals))
Re:What's Coming in Python 3.8 by stefco_ on Wednesday July 17, 2019 @09:37PM (#20465881)
This is somewhat cleaner, and I also use this idiom when things get ugly with the inline formatting shown above. But my point is that none of these are very elegant for an extremely common use case. Throw this block in the middle of some complex code with a few try/except and raise statements and it still looks confusing. Having two extra temp variables and statements per error in a function that's just doing control flow and wrapping unsafe code can double your local variable count and number of statements across the whole function. AFAIK, there has been no elegant solution to this common problem until f-strings came around; the only decently clean one is using printf-style format strings with the old-style operator, but outside of terseness I find it less readable.
Re:What's Coming in Python 3.8 by JoBrad on Monday July 29, 2019 @08:59AM (#20554114)
Alternate “clean” way, but sort of hacky.

  raise ValueError(“File exists, not uploading: {filename} -> {bucket}, {key}”.format(**locals()))