0

New to python. I am getting:

Invalid syntax line 1

I understand that the fstring error can show up on line one. These lines are pretty much taken from this page in the python docs. There is syntax I am unfamiliar with {err=}. I tried searching but the = is so ubiquitous it's like a needle in a haystack.

What is wrong with what is below? I assume it is somehow connected to the =. If I remove the = then the error flag goes away.

What does the = do?

The two places that use this error handling look like this:

except  BaseException as err:
    print(f"Shadow retrieval exception: {err=}, {type(err)=}")

and

except  BaseException as err:
    print(f"Unexpected {err=}, {type(err)=}")
wjandrea
  • 28,235
  • 9
  • 60
  • 81
Eric Snyder
  • 1,816
  • 3
  • 22
  • 46
  • What version of Python are you running? The `=` was added in 3.8. See [docs](https://docs.python.org/3/reference/lexical_analysis.html#f-strings) and [What’s New In Python 3.8](https://docs.python.org/3/whatsnew/3.8.html#f-strings-support-for-self-documenting-expressions-and-debugging) – wjandrea Oct 03 '22 at 22:26
  • That's a typing shortcut. `f"Hello {i=}"`, if i is 3, will retuirn `"Hello i=3"`. That is, it enters literal `"i="` and then the value of i. – Tim Roberts Oct 03 '22 at 22:26
  • Thank you all. I was developing in 3.7.3. That was leading to the use of the `=` being flagged an error. – Eric Snyder Oct 04 '22 at 12:27

0 Answers0