Re:Pattern matching accepted for Python
by sumzup on Tuesday February 09, 2021 @05:40PM
(#26083431)
[ Parent
| on HN ]
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
Re:Pattern matching accepted for Python
by staticassertion on Tuesday February 09, 2021 @06:14PM
(#26083802)
Something along the lines of...
code = 'f"{input()} {x}"'
lambda x: eval(code)
(Please don't do this)
Re:Pattern matching accepted for Python
by staticassertion on Tuesday February 09, 2021 @11:36PM
(#26085783)
code = 'f"here it is {eval(input())}"'
(lambda: eval(code))()
k, there we goYes, I'll stick to using str.format :)
Re:Pattern matching accepted for Python
by klyrs on Wednesday February 10, 2021 @01:33AM
(#26086230)
That isn't the purpose for f-strings. You still have % and .format