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

Python f-strings don't work like that. The expression is evaluated when the string constant is defined, not when it's used, so your scenario is "code execution leads to code execution".

  >>> def server(userdata):
  ...   print("Your data:", userdata)
  ... 
  >>> value = f"Printing... {print('Eval!')}"
  Eval!
  >>> server(value)
  Your data: Printing... None


Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

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

Search: