Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What if "hello {x}" is not a static string but was read from somewhere else?

Surely this would not work:

  greeting = "hello {x}"
  greet = lambda x: f greeting


Something along the lines of...

    code = 'f"{input()} {x}"'

    lambda x: eval(code)
(Please don't do this)


    code = 'f"here it is {eval(input())}"'
    (lambda: eval(code))()
k, there we go


Yes, I'll stick to using str.format :)


That isn't the purpose for f-strings. You still have % and .format


You can’t use f-strings for that.


That was exactly my point.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: